This file contains hidden or 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 reverseString(str) { | |
| return str.split('').reverse().join(''); | |
| } | |
| reverseString('hello'); |
This file contains hidden or 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 palindrome(str) { | |
| return str.replace(/\W|_/gi, '').toLowerCase() === str.split('').reverse().join().replace(/\W|_/gi, '').toLowerCase() ? true : false; | |
| } | |
| palindrone('race car'); |
This file contains hidden or 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 factorialize(num) { | |
| if(num === 0){ | |
| return 1; | |
| } | |
| return num * factorialize(num - 1); | |
| } | |
| factorialize(5); |
This file contains hidden or 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 add() { | |
| if(arguments.length > 1){ | |
| return Array.from(arguments).every(function(val){ | |
| return typeof val === 'number'; | |
| }) ? Array.from(arguments).reduce(function(prev, current){ | |
| return prev + current | |
| }) : undefined; | |
| }else if(typeof arguments[0] === 'number'){ | |
| var x = arguments[0]; | |
| return function(y){ |
This file contains hidden or 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) { | |
| return str.split(' ').map(function(val){ | |
| return String.fromCharCode(parseInt(val, 2)); | |
| }).join('').replace(',', ' '); | |
| } | |
| 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 hidden or 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) { | |
| return Array.apply(0, Array(num + 1)) | |
| .map(function(x, y){ | |
| return y | |
| }).filter(function (i){ | |
| return (i > 1) && Array | |
| .apply(0, Array(1 + ~~Math.sqrt(i))) | |
| .every(function(x, y){ | |
| return (y < 2) || (i % y !== 0) | |
| }); |
This file contains hidden or 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) { | |
| // I'm a steamroller, baby | |
| arr = Array.prototype.concat.apply([], arr); | |
| return arr.some(Array.isArray) ? steamroller(arr) : arr; | |
| } | |
| steamroller([1, [2], [3, [[4]]]]); |
This file contains hidden or 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 unite(arr1, arr2, arr3) { | |
| return Array.from(arguments).reduce(function(a, b){ | |
| return a.concat(b).filter(function(val,pos,arr){ | |
| return arr.indexOf(val) === pos; | |
| }); | |
| }); | |
| } | |
| unite([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]); |
This file contains hidden or 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 diff(arr1, arr2) { | |
| return newArr = arr1.filter(function(val){ | |
| return arr2.indexOf(val) === -1; | |
| }).concat(arr2.filter(function(val){ | |
| return arr1.indexOf(val) === -1; | |
| })); | |
| } | |
| diff(['diorite', 'andesite', 'grass', 'dirt', 'pink wool', 'dead shrub'], ['diorite', 'andesite', 'grass', 'dirt', 'dead shrub']); |
This file contains hidden or 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 titleCase(str) { | |
| return str.split(' ').map(function(val){ | |
| return val.charAt(0).toUpperCase() + val.slice(1).toLowerCase(); | |
| }).join(' '); | |
| } | |
| titleCase("sHoRt AnD sToUt"); |
OlderNewer