This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits. | |
Example | |
"abcde" -> 0 # no characters repeats more than once | |
"aabbcde" -> 2 # 'a' and 'b' | |
"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (`b` and `B`) | |
"indivisibility" -> 1 # 'i' occurs six times | |
"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice | |
"aA11" -> 2 # 'a' and '1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. | |
For example: | |
url = "http://github.com/carbonfive/raygun" -> domain name = "github" | |
url = "http://www.zombie-bites.com" -> domain name = "zombie-bites" | |
url = "https://www.cnet.com" -> domain name = cnet" | |
**/ | |
function domainName(url) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements. | |
e.g. | |
moveZeros([false,1,0,1,2,0,1,3,"a"]) // returns[false,1,1,2,1,3,"a",0,0] | |
**/ | |
function moveZeros(arr) { | |
//code me | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Complete the capitalizeFirstLetter below while being sure to capitalize the initial letter of each word in the provided string. | |
e.g. | |
const str = "How can mirrors be real if our eyes aren't real" | |
str.capitalizeFirstLetter() //-> "How Can Mirrors Be Real If Our Eyes Aren't Real" | |
**/ | |
String.prototype.capitalizeFirstLetter = function () {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function uncompress(str) { | |
var result = str; | |
while (/\d/.test(result)) { | |
var start = result.lastIndexOf("(") | |
var end = result.indexOf(")") | |
var rounds = parseInt(result[start - 1], 10); | |
var repeats = result.substring(start + 1, end).repeat(rounds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.myMap = function(callback) { | |
const result = []; | |
for(let i = 0; i < this.length; i++) { | |
result.push(callback(this[i], i, this)); | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function undefinedToNull(arg) { | |
if (arg == undefined || arg == null) return null | |
if (Array.isArray(arg)) return arg.map(undefinedToNull) | |
if (arg.constructor === Object) { | |
Object.keys(arg).forEach(key => { | |
arg[key] = undefinedToNull(arg[key]) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. `key` should be stable, predictable and unique amongst the list items and their children. | |
2. Split Presentational and container components. | |
3. Presentational components only hold the markup. | |
4. Always make the presentational component a functional component. | |
5. A container holds the state or other business conditions. | |
6. Use `React.PureComponent` for Container and `React.memo` for Presentational component. | |
7. Use ternary operator as little as possible in both components and the render method. | |
8. Avoid using context in the application. | |
9. Always define default props. | |
10. Avoid using nested state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function numberToOrdinal(input) { | |
try { | |
if(typeof input !== 'number') { | |
throw('Please provide valid number'); | |
} | |
const lastDigit = input % 10; | |
let ordinal = ''; | |
if(lastDigit === 1 && input !== 11) { | |
ordinal = 'st'; | |
} else if (lastDigit === 2 && input !== 12) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*We know the purpose of classes in sense of programming concepts. | |
In JavaScript `class` is the makeover upon traditional prototype-inheritance. | |
*/ | |
//ES5 Approach: | |
function Person(first, last) { | |
this.first = first; | |
this.last = last; | |
} |
NewerOlder