Answers for "js accumulator"

12

javascript sum of array

const sum = arr => arr.reduce((a, b) => a + b, 0);
Posted by: Guest on July-03-2020
6

.reduce mdn

arr.reduce(callback( accumulator, currentValue[, index[, array]] )[, initialValue])
Posted by: Guest on March-11-2020
2

reduce method

The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in single output value.

The reducer function takes four arguments:
Accumulator (acc)
Current Value (cur)
Current Index (idx)
Source Array (src)

//syntax
arr.reduce(callback( accumulator, currentValue, [, index[, array]] )[, initialValue])
//example flatten an array

let flattened = [[0, 1], [2, 3], [4, 5]].reduce(
  ( accumulator, currentValue ) => accumulator.concat(currentValue),
  []
)
Posted by: Guest on September-09-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language