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 convert(str) { | |
// :) | |
return str.replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """).replace(/'/g,"'"); | |
} | |
convert("Dolce & Gabbana"); |
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 spinalCase(str) { | |
return str.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase().replace(/[_\s]/g,"-"); | |
} | |
spinalCase("Teletubbies say Eh-oh"); | |
spinalCase('thisIsSpinalTap'); |
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 sumFibs(num) { | |
var i = 0; | |
var arr = [0,1]; | |
while(arr[i] + arr[i+1] <= num){ | |
arr.push(arr[i] + arr[i+1]); | |
i++; | |
} | |
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 sumPrimes(num) { | |
var sum = 0; | |
for(var i = 2; i <= num; i++){ | |
if(isPrime(i) === true){ | |
sum += i; | |
} | |
} | |
return sum; | |
} |
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 smallestCommons(arr) { | |
return numInRange(arr).reduce(function(a,b){ | |
return lcm(a,b); | |
}); | |
} | |
function gcd (x, y) { | |
return (x % y === 0) ? y : gcd(y, x % y); | |
} |
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 find(arr, func) { | |
return arr.filter(func).shift(); | |
} | |
find([1, 2, 3, 4], function(num){ return num % 2 === 0; }); |
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 drop(arr, func) { | |
var first_elem = arr.filter(func).shift(); | |
return (first_elem === undefined) ? [] : arr.slice(arr.indexOf(first_elem)); | |
} | |
drop([1, 2, 3, 4], function(n) {return n > 5;}); | |
drop([1, 2, 3], function(n) {return n < 3; }); |
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 steamroller(arr) { | |
return flatten(arr); | |
} | |
function flatten(arr) { | |
return arr.reduce(function(flat,toBeFlatten){ | |
return flat.concat(Array.isArray(toBeFlatten) ? flatten(toBeFlatten) : toBeFlatten); | |
}, []); | |
} |
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 binaryAgent(str) { | |
var new_str = str.split(" ").map(function(x){ | |
return String.fromCharCode(parseInt(x,2)); | |
}); | |
return new_str.join(""); | |
} | |
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"); |
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 every(collection, pre) { | |
for(var x in collection){ | |
if(collection[x].hasOwnProperty(pre)){ | |
if(!collection[x][pre]){ | |
return false; | |
} | |
}else{ | |
return false; | |
} | |
} |