mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Bump to v4.16.4.
This commit is contained in:
24
transform.js
24
transform.js
@@ -4,6 +4,7 @@ var arrayEach = require('./_arrayEach'),
|
||||
baseIteratee = require('./_baseIteratee'),
|
||||
getPrototype = require('./_getPrototype'),
|
||||
isArray = require('./isArray'),
|
||||
isBuffer = require('./isBuffer'),
|
||||
isFunction = require('./isFunction'),
|
||||
isObject = require('./isObject'),
|
||||
isTypedArray = require('./isTypedArray');
|
||||
@@ -39,22 +40,23 @@ var arrayEach = require('./_arrayEach'),
|
||||
* // => { '1': ['a', 'c'], '2': ['b'] }
|
||||
*/
|
||||
function transform(object, iteratee, accumulator) {
|
||||
var isArr = isArray(object) || isTypedArray(object);
|
||||
iteratee = baseIteratee(iteratee, 4);
|
||||
var isArr = isArray(object),
|
||||
isArrLike = isArr || isBuffer(object) || isTypedArray(object);
|
||||
|
||||
iteratee = baseIteratee(iteratee, 4);
|
||||
if (accumulator == null) {
|
||||
if (isArr || isObject(object)) {
|
||||
var Ctor = object.constructor;
|
||||
if (isArr) {
|
||||
accumulator = isArray(object) ? new Ctor : [];
|
||||
} else {
|
||||
accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
|
||||
}
|
||||
} else {
|
||||
var Ctor = object && object.constructor;
|
||||
if (isArrLike) {
|
||||
accumulator = isArr ? new Ctor : [];
|
||||
}
|
||||
else if (isObject(object)) {
|
||||
accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
|
||||
}
|
||||
else {
|
||||
accumulator = {};
|
||||
}
|
||||
}
|
||||
(isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
|
||||
(isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
|
||||
return iteratee(accumulator, value, index, object);
|
||||
});
|
||||
return accumulator;
|
||||
|
||||
Reference in New Issue
Block a user