Refactor reduceRight and modify a _.difference benchmark.

Former-commit-id: b70272ac5316fe1bee52b9611a1a5ea4d761dd3c
This commit is contained in:
John-David Dalton
2012-09-22 15:55:57 -07:00
parent 1ca26ce676
commit 8532dc4b75
3 changed files with 16 additions and 16 deletions

View File

@@ -2220,19 +2220,23 @@
if (!collection) {
return accumulator;
}
var length = collection.length,
var iteratee = collection,
length = collection.length,
noaccum = arguments.length < 3;
if (length !== +length) {
var props = keys(collection);
length = props.length;
} else if (noCharByIndex && toString.call(collection) == stringClass) {
iteratee = collection.split('');
}
return reduce(collection, function(accumulator, value, index, object) {
var index = props ? props[--length] : --length;
return noaccum
? (noaccum = false, object[index])
: callback.call(thisArg, accumulator, object[index], index, object);
}, accumulator);
forEach(collection, function(value, index, object) {
index = props ? props[--length] : --length;
accumulator = noaccum
? (noaccum = false, iteratee[index])
: callback.call(thisArg, accumulator, iteratee[index], index, object);
});
return accumulator;
}
/**