reduce (1) 썸네일형 리스트형 JS - Array.prototype.reduce() 구현하기 reduce()** **메서드는 배열의 각 요소에 대해 주어진 **리듀서**(reducer) 함수를 실행하고, 하나의 결과값을 반환합니다. - mdn const array1 = [1, 2, 3, 4]; // 0 + 1 + 2 + 3 + 4 const initialValue = 0; const sumWithInitial = array1.reduce( (previousValue, currentValue) => previousValue + currentValue, initialValue ); console.log(sumWithInitial); // expected output: 10 다음과 같이 배열의 총 합을 구할때 많이 사용하는 reduce 함수를 직접 구현해보겠습니다. const arr = [1,2,3,.. 이전 1 다음