We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dbd0734 commit c50caecCopy full SHA for c50caec
src/arrays.js
@@ -22,10 +22,11 @@ const map = (elements, cb) => {
22
return mappedArr;
23
};
24
25
-const reduce = (elements, cb, memo = elements.shift()) => {
+const reduce = (elements, cb, startingValue = elements.shift()) => {
26
// Combine all elements into a single value going from left to right.
27
// Elements will be passed one by one into `cb`.
28
// `memo` is the starting value. If `memo` is undefined then make `elements[0]` the initial value.
29
+ let memo = startingValue;
30
each(elements, (item) => {
31
memo = cb(memo, item);
32
});
0 commit comments