배열의 요소들을 더해 계산한 후 결과값을 실행한다.
const array = [1, 2, 3, 4, 5]
const reducer = (prevValue, currValue) => prevValue + currValue;
//1, 2, 3, 4, 5
console.log(array.reduce(reducer));
//결과 15
배열의 요소들을 더해 계산한 후 결과값을 실행한다.
const array = [1, 2, 3, 4, 5]
const reducer = (prevValue, currValue) => prevValue + currValue;
//1, 2, 3, 4, 5
console.log(array.reduce(reducer));
//결과 15
Comments