Skip to content

Commit

Permalink
Tweaks to Issue jashkenas#53
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Nov 1, 2010
1 parent 974ae99 commit 51e327f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@
// **Reduce** builds up a single result from a list of values, aka `inject`,
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
var initial = memo !== void 0;
if (nativeReduce && obj.reduce === nativeReduce) {
if (context) iterator = _.bind(iterator, context);
var args = [iterator];
if (memo !== undefined) args.push(memo);
return obj.reduce.apply(obj, args);
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
}
each(obj, function(value, index, list) {
if (memo === undefined && index == 0) {
if (!initial && index === 0) {
memo = value;
} else {
memo = iterator.call(context, memo, value, index, list);
Expand Down

0 comments on commit 51e327f

Please sign in to comment.