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 gatherArgs(fn) { | |
return function gatheredFn(...argsArr) { | |
return fn( argsArr ); | |
}; | |
} | |
function gatherArgProps(fn,propOrder = []) { | |
return function gatheredFn(...args) { | |
return fn( | |
zip( propOrder, 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
function curryProps(fn,arity = 1) { | |
return (function nextCurried(prevArgs){ | |
return function curried(nextArg){ | |
if (!nextArg || typeof nextArg != "object") { | |
nextArg = { value: nextArg }; | |
} | |
var [key] = Object.keys( nextArg ); | |
var args = Object.assign( {}, prevArgs, { [key]: nextArg[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
function *zipIterators(...its) { | |
its = its.map(it => (!it.next && it[Symbol.iterator]) ? it[Symbol.iterator]() : it); | |
while (its.length > 0) { | |
let entry = []; | |
let itsCopy = [...its]; | |
let it; | |
while (it = itsCopy.shift()) { | |
its.shift(); | |
let res = it.next(); |
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
Object.defineProperty(Number.prototype,Symbol.iterator,{ | |
*value({ start = 0, step = 1 } = {}) { | |
var inc = this > 0 ? step : -step; | |
for (let i = start; Math.abs(i) <= Math.abs(this); i += inc) { | |
yield i; | |
} | |
}, | |
enumerable: false, | |
writable: true, | |
configurable: true |
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
Object.defineProperty(Object.prototype,Symbol.toStringTag,{ | |
get() { | |
return JSON.stringify(this); | |
}, | |
set(v) { | |
Object.defineProperty(Object.prototype,Symbol.toStringTag,{ | |
value: v, | |
enumerable: false, | |
writable: true, | |
configurable: true |
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
// Doesn't throw an error, but doesn't return an object | |
const getObj = () => { a: 1 }; | |
console.log(getObj()); //=> val 'undefined' : void | |
// Reason: It looks like an arrow function returning an object, but it isn't. | |
// It's an arrow function with a function body (containing a labeled | |
// statement) that returns nothing. | |
const getObj = () => | |
{ // <- Start function body | |
a: // <- A label to use when break/continue; e.g. break a; |
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 Foo { | |
one() { | |
return this.x; | |
} | |
} | |
class Bar extends Foo { | |
two() { | |
return this.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
// EAT: Eager Async Thunk, aka "promise" | |
function gimmeFutureVal(x) { | |
var fs = [], v; | |
doSomethingAsync(x,function res(r){ | |
if (fs.length > 0) { | |
v = r; | |
while (fs.length > 0) { | |
fs.shift()(v); |
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
// maxOnlyEven(): undefined | |
// maxOnlyEven(1): undefined | |
// maxOnlyEven(1,3): undefined | |
// maxOnlyEven(1,4): 4 | |
// maxOnlyEven(2): 2 | |
// maxOnlyEven(undefined,2): 2 | |
// maxOnlyEven(2,4): 4 | |
function maxOnlyEven(num1,num2) { | |
var A = num1 % 2 == 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
// examples... | |
// | |
// maxEven(): undefined | |
// maxEven(1): undefined | |
// maxEven(1,13): undefined | |
// maxEven(-Infinity,Infinity): undefined | |
// maxEven(0): 0 | |
// maxEven(-4,3,-6,0,5,2,1,9): 2 | |
function maxEven(num1,...nums) { |