mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Refactor reduceRight and modify a _.difference benchmark.
Former-commit-id: b70272ac5316fe1bee52b9611a1a5ea4d761dd3c
This commit is contained in:
18
lodash.js
18
lodash.js
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user