Skip to content

Commit c50caec

Browse files
SunJieMingSunJieMing
authored andcommitted
Updated solution
1 parent dbd0734 commit c50caec

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/arrays.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ const map = (elements, cb) => {
2222
return mappedArr;
2323
};
2424

25-
const reduce = (elements, cb, memo = elements.shift()) => {
25+
const reduce = (elements, cb, startingValue = elements.shift()) => {
2626
// Combine all elements into a single value going from left to right.
2727
// Elements will be passed one by one into `cb`.
2828
// `memo` is the starting value. If `memo` is undefined then make `elements[0]` the initial value.
29+
let memo = startingValue;
2930
each(elements, (item) => {
3031
memo = cb(memo, item);
3132
});

0 commit comments

Comments
 (0)