ITERATORS: The .reduce() Method

PHOTO EMBED

Tue Oct 05 2021 13:11:30 GMT+0000 (Coordinated Universal Time)

Saved by @ianvalentino #javascript

const newNumbers = [1, 3, 5, 7];

const newSum = newNumbers.reduce((accumulator, currentValue) => {
  console.log('The value of accumulator: ', accumulator);
  console.log('The value of currentValue: ', currentValue);
  return accumulator + currentValue
}, 10);

// es como: .reduce(A, B) | .reduce(A:(a)=>{}, B)

console.log(newSum);
content_copyCOPY

Exercise with .reduce() method.

https://www.codecademy.com/courses/introduction-to-javascript/lessons/javascript-iterators/exercises/reduce