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 LinkedListToArr(list) { | |
| var result = [list.value], | |
| obj = list; | |
| while (obj.next) { | |
| result.push(obj.next.value) | |
| obj = obj.next; | |
| } | |
| return result.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
| let instance = null; | |
| class Cashe { | |
| constructor() { | |
| if (!instance) { | |
| instance = this; | |
| } | |
| this.time = new Date(); | |
| return instance; | |
| } |
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 arr = [10, 12, 15, 21]; | |
| for (var i = 0; i < arr.length; i++) { | |
| setTimeout(function() { | |
| console.log("Index: " + i + ", element: " + arr[i]); | |
| }, 3000); | |
| } | |
| // -> Index: 4, element: undefined(printed 4 times) |
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
| // type 𝔹 := ∀ α, α → α → α | |
| // T : 𝔹 | |
| const T = a => b => a; | |
| // F : 𝔹 | |
| const F = a => b => b; | |
| // iff : ∀ α, 𝔹 → α → α → α | |
| const iff = c => a => b => c(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 average = (...arg) => | |
| arg.reduce((total, amount, index) => { | |
| total += amount; | |
| return index === arg.length - 1 ? total / arg.length : total; | |
| }); |
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 count = arr => arr.reduce((acc, item) => | |
| ({ ...acc, [item]: acc[item] ? acc[item] + 1 : 1 }), {}); | |
| // const count = arr => | |
| // arr.reduce((acc, item) => ({ ...acc, [item]: (acc[item] || 0) + 1 }), {}); |
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 = arr => | |
| Array.isArray(arr) | |
| ? arr.reduce((done, curr) => done.concat(flatten(curr)), []) | |
| : arr; |
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 clone = x => [...x]; | |
| const push = x => y => [...x, y]; | |
| const pop = x => x.slice(0, -1); | |
| const unshift = y => x => [y, ...x]; | |
| const shift = x => x.slice(1); |
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 map = (fn, arr) => | |
| arr.reduce((acc, item, index, arr) => { | |
| return acc.concat(fn(item, index, arr)); | |
| }, []); |
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 filter = (fn, arr) => | |
| arr.reduce((newArr, item) => { | |
| return fn(item) ? newArr.concat([item]) : newArr; | |
| }, []); |
OlderNewer