DEV Community

Discussion on: 5 Anti-Patterns to Avoid When Working With Collections in JavaScript

Collapse
 
larrybolt profile image
Larry Boltovskoi

Perhaps an inline function there would be less confusing if it's a one-time, otherwise having a function taking the array as a parameter and output an array as sums, and having a clear name what it does.

const numbers = [[1, 2], [2, 2], [18, 1], [4, 5], [8, 9], [0, 0]]
const numberSums = numbers.map(([a,b]) => a+b)
// [3, 4, 19, 9, 17, 0]
Collapse
 
suraneti profile image
Suraneti Rodsuwan

If an input is a heavy huge array, using simple for-loop or while-loop for me is the best choice for optimized performance.