my rule for .reduce(): only use it when the result has the same type as the items and the reducer is associative, like
.reduce((a, b) => a + b, 0)
summing some numbers
multiplying some numbers
building up a list or object
just about anything else (use a loop)
-
-
If the aggregate is being spread into the return value of a reducer, could the VM safely reuse the old object instead of allocating a new one? things.reduce((thing, result) => ({ ...result, [http://thing.id ]: thing }), {}) without allocating a new {} on every iteration.
-
A sufficiently smart compiler, etc. It sounds complicated to get right, though, and this does not seem like a very common/idiomatic pattern (?).
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.