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 = function* (iterable, cond) { | |
| const iterator = iterable[Symbol.iterator](); | |
| let cursor = iterator.next(); | |
| do { | |
| const {value} = cursor; | |
| if (cond(value)) { | |
| yield value; | |
| } | |
| } while (!(cursor = iterator.next()).done); | |
| }; |
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 sum = (...args) => | |
| Object.assign( | |
| sum.bind(null, ...args), | |
| {valueOf: () => args.reduce((acc, cur) => acc + cur, 0)} | |
| ); | |
| export default sum; |
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 unarrow = arrowFunc => { | |
| const arrowFuncDefinition = arrowFunc.toString(); | |
| const hasEnclosingBraces = arrowFuncDefinition.indexOf('}') === arrowFuncDefinition.length - 1; | |
| const newDefinition = | |
| `return function${ | |
| hasEnclosingBraces ? | |
| arrowFuncDefinition.replace('=>', '') : | |
| arrowFuncDefinition.replace('=>', '{return ') + '}' | |
| }`; |
NewerOlder