Higher-Order Functions¶
Functional helpers that take other functions as arguments.
Each helper expects a function value of the form (value, index, list) -> ... unless noted.
MAP(list, fn)→ transforms each element.FILTER(list, fn)→ keeps elements wherefnis truthy.REDUCE(list, init, fn)→ accumulates frominit.SOME(list, fn)/EVERY(list, fn)→ booleans for any/all; empty lists returnfalse/truerespectively.FIND(list, fn)→ first matching value ornull; returnsnullon empty lists.APPLY(fn, ...args)→ calls a function value with arbitrary args.IS_FUNCTION(x)→ tests if a value is callable.
Truthy rules: null and false are falsey; numbers are falsey only when 0; strings are falsey only when empty.
Run it: Higher-order helpers example.