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
| const getTrib = n => { | |
| let [x, y, z] = [0, 1, 1] | |
| for (let i = 2; i < n; i += 1) { | |
| [x, y, z] = [y, z, x + y + z] | |
| } | |
| return x | |
| } |
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
| const make = x => { | |
| const fn = h => x => (typeof x === 'function') | |
| ? h(x) | |
| : fn(y => y(x, h(y))) | |
| return fn(y => x); | |
| } | |
| const sum = (a, b) => a + b | |
| const mul = (a, b) => a * b |
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
| const deepClone = (obj) => { | |
| if (obj === null) return null | |
| return Object.keys(obj).reduce((acc, key) => { | |
| acc[key] = Array.isArray(obj[key]) | |
| ? [...obj[key]] | |
| : typeof obj[key] === 'object' | |
| ? deepClone(obj[key]) | |
| : obj[key] |
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
| const flatten = (obj, prefix = '') => | |
| Object.keys(obj).reduce((acc, k) => { | |
| const pre = prefix.length ? prefix + '.' : '' | |
| if (typeof obj[k] === 'object') { | |
| Object.assign(acc, flatten(obj[k], pre + k)) | |
| } | |
| else acc[pre + k] = obj[k] | |
| return acc | |
| }, {}) |
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
| const mergeObjects = ([...args]) => | |
| args.reduce( | |
| (acc, obj) => | |
| Object.keys(obj).reduce((_, key) => { | |
| acc[key] = acc[key] ? [...acc[key], obj[key]] : [obj[key]] | |
| return acc | |
| }, {}), | |
| {} | |
| ) |
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
| abusaidm.html-snippets-0.2.1 | |
| bradgashler.htmltagwrap-0.0.7 | |
| christian-kohler.npm-intellisense-1.3.0 | |
| christian-kohler.path-intellisense-1.4.2 | |
| dbaeumer.vscode-eslint-1.9.0 | |
| dsznajder.es7-react-js-snippets-2.3.0 | |
| eamodio.gitlens-9.8.2 | |
| eg2.vscode-npm-script-0.3.7 | |
| esbenp.prettier-vscode-1.9.0 | |
| flowtype.flow-for-vscode-1.1.3 |
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
| const before = (count, fn) => { | |
| let called = 0; | |
| return (...args) => { | |
| if (called >= count) return; | |
| called += 1; | |
| return fn(...args); | |
| }; | |
| }; |
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
| class Sleep { | |
| constructor(timeout) { | |
| this.timeout = timeout; | |
| } | |
| then(resolve, reject) { | |
| const startTime = Date.now(); | |
| setTimeout(() => resolve(Date.now() - startTime), this.timeout); | |
| } | |
| } |
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
| const swap = (items, firstIndex, secondIndex) => { | |
| const temp = items[firstIndex]; | |
| items[firstIndex] = items[secondIndex]; | |
| items[secondIndex] = temp; | |
| }; | |
| const partition = (items, left, right) => { | |
| let pivot = items[Math.floor((right + left) / 2)]; | |
| let i = left; | |
| let j = right; |
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
| const bubblesort = arr => { | |
| const count = arr.length - 1; | |
| let max = null; | |
| for (let i = 0; i < count; i++) { | |
| for (let j = 0; j < count - i; j++) { | |
| if (arr[j] > arr[j + 1]) { | |
| max = arr[j]; | |
| arr[j] = arr[j + 1]; | |
| arr[j + 1] = max; |
NewerOlder