DEV Community

Discussion on: Please don't "overchain" array methods

Collapse
ctimmerman profile image
Cees Timmerman • Edited on

JSPerf is down atm, but i'm pretty sure this is faster and easier to read:

const nums = [ -2, -1, 0, 1, 2 ]
var sum = 0; for(var i = 0; i < nums.length; ++i) sum += nums[i]**2 * 3
Collapse
somedood profile image
Basti Ortiz Author

I mean... yes, it definitely is, but the point of my article is not to promote the most performant code; rather, the point of this article is to remind the reader to be wary of "overchaining" array methods because of its implications on the number of array iterations. 😅