File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ var _ = {};
163
163
} ) ;
164
164
} ;
165
165
166
- // Reduces an array or object to a single value by repetitively calling
166
+ // Reduces an array of object to a single value by repetitively calling
167
167
// iterator(previousValue, item) for each item. previousValue should be
168
168
// the return value of the previous iterator call.
169
169
//
@@ -177,6 +177,11 @@ var _ = {};
177
177
// return total + number;
178
178
// }, 0); // should be 6
179
179
_ . reduce = function ( collection , iterator , accumulator ) {
180
+ var tot = accumulator || 0 ;
181
+ _ . each ( collection , function ( val ) {
182
+ tot = iterator ( tot , val ) ;
183
+ } ) ;
184
+ return tot ;
180
185
} ;
181
186
182
187
// Determine if the array or object contains a given value (using `===`).
You can’t perform that action at this time.
0 commit comments