Member-only story
Your Iterator Helper Chain Runs Once. The Second Loop Gets Nothing.
values().filter().map() looks like an array chain, but it is a single-use cursor. Here is the bug and three fixes.
Ferid Brković
7 min read7 hours ago
Press enter or click to view image in full size
orders.values().filter(isPaid).map(toTotal) reads like the array chain you have written a thousand times. Loop over the result and you get the paid totals. Loop over it again and you get nothing: no error, no warning, an empty pass.
A report built on that chain computes a correct sum, a count of zero and an average of Infinity .
Three numbers, two of them wrong
Iterator helpers put filter , map , take , drop and flatMap directly on iterators, so you can skip the intermediate arrays. MDN marks Iterator.prototype.map() as working across the latest browsers since March 2025, and the Node.js 22 release announcement lists iterator helpers among the features of its V8 12.4 update.…