Functional Programming
WIP.
Underscore / Lodash
Lodash Chaining:
explicit, similar to underscore:
_.chain(numbers).map(n => n/2 === 0).value()
implicit, if the result is a single value:
_(numbers).map(n => n/2 === 0).sum()
Difference between .throttle and .debounce?
throttle: At most that fast, usually used when invoking source happens really frequently. Such as when typing to seach, don't send too many requests, scroll, mouse move, etc.
debounce: wait till no change. Such as calc layout when resize is finished.
Convert an object into a list of [key, value] pairs.
how to union with array?
_.each cannot break out
It's also good to note that an each loop cannot be broken out of — to break, use _.find instead.
use _.find
for array and _.findKey(obj, (v, k)=>())
for object
How to convert a details array to a map?
This is a collection reduces to a single object. Use reduce
.
Borrowed from: https://github.com/rackt/react-router/blob/master/examples/sidebar/data.js
Last updated