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
| var recoverSecret = function(triplets) { | |
| let duplets = []; | |
| let res = ''; | |
| triplets.forEach(trip => { | |
| duplets.push(trip.slice(0,2).join('')); | |
| duplets.push(trip.slice(1, 3).join('')); | |
| }) | |
| duplets = duplets.filter((value, index, array) => array.indexOf(value) === index) | |
| let word = getWord(duplets); | |
| while(word) { |
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 removeK(k){ | |
| return k * (3*k + 1) / 2; | |
| } |
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 dup(s) { | |
| return s.map((str) => Array.from(str).filter((v, i, arr) => arr[i - 1] !== v).join('')) | |
| }; |
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
| num1 = ('' + num1).split('').reverse() | |
| num2 = ('' + num2).split('').reverse() | |
| let max = Math.max(num1.length, num2.length) | |
| let str = []; | |
| for(let i = 0; i < max; i++) | |
| str.push((parseInt(num1[i]) || 0) + (parseInt(num2[i]) || 0)) | |
| num1 = str.reverse().join(''); | |
| return parseInt(num1); |
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
| num1 = ('' + num1).split('').reverse() | |
| num2 = ('' + num2).split('').reverse() | |
| let max = Math.max(num1.length, num2.length) | |
| let str = []; | |
| for(let i = 0; i < max; i++) | |
| str.push((parseInt(num1[i]) || 0) + (parseInt(num2[i]) || 0)) | |
| num1 = str.reverse().join(''); | |
| return parseInt(num1); |
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
| var RomanNumerals = { | |
| toRoman : function (number) { | |
| var ret = ''; | |
| while(number > 0) { | |
| if(number/1000 >= 1) { | |
| ret += 'M'; | |
| number -=1000; | |
| } else if(number/900 >= 1) { | |
| ret += 'CM'; | |
| number -=900; |
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
| snail = function(array) { | |
| if(array.length === 0) return []; | |
| if(array.length === 1) return array[0]; | |
| let top = array[0].slice(0,-1); | |
| let right = array.map(a => a[a.length - 1]); | |
| let bottom = array[array.length - 1].slice(0, -1).reverse(); | |
| let left = array.slice(1, -1).map(b => b[0]).reverse(); | |
| let inner = array.slice(1, -1).map(c => c.slice(1, -1)); | |
| return [].concat(top, right, bottom, left, snail(inner)); | |
| } |
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 sum(matrix) { | |
| let i = 0; | |
| let sum = 0; | |
| matrix.forEach(array => { | |
| sum += array[i]; | |
| sum += array[array.length - i -1] | |
| i++; | |
| if(i >= array.lenght) { | |
| i = 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
| Array.prototype.sameStructureAs = function (other) { | |
| Array.prototype.status = Array.prototype.status || true; | |
| if(this.length != other.length){ | |
| Array.prototype.status = false; | |
| return false; | |
| } | |
| for(var index = 0; index < this.length; index++) | |
| { |
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 permutations(string) { | |
| var arr = string.split(''), tmp = arr.slice(), heads = [], out = []; | |
| if(string.length == 1) return [string]; | |
| arr.forEach(function(v, i, arr) { | |
| if(heads.indexOf(v) == -1) { | |
| heads.push(v); | |
| tmp.splice(tmp.indexOf(v), 1); | |
| permutations(tmp.join('')).forEach(function(w) {out.push(v + w);}); | |
| tmp.push(v); | |
| } |
OlderNewer