MCPcopy
hub / github.com/lodash/lodash / transform

Function transform

lodash.js:13887–13908  ·  view source on GitHub ↗

* An alternative to `_.reduce`; this method transforms `object` to a new * `accumulator` object which is the result of running each of its own * enumerable string keyed properties thru `iteratee`, with each invocation * potentially mutating the `accumulator` object. If `accumulator` i

(object, iteratee, accumulator)

Source from the content-addressed store, hash-verified

13885 * // => { '1': ['a', 'c'], '2': ['b'] }
13886 */
13887 function transform(object, iteratee, accumulator) {
13888 var isArr = isArray(object),
13889 isArrLike = isArr || isBuffer(object) || isTypedArray(object);
13890
13891 iteratee = getIteratee(iteratee, 4);
13892 if (accumulator == null) {
13893 var Ctor = object && object.constructor;
13894 if (isArrLike) {
13895 accumulator = isArr ? new Ctor : [];
13896 }
13897 else if (isObject(object)) {
13898 accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
13899 }
13900 else {
13901 accumulator = {};
13902 }
13903 }
13904 (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
13905 return iteratee(accumulator, value, index, object);
13906 });
13907 return accumulator;
13908 }
13909
13910 /**
13911 * Removes the property at `path` of `object`.

Callers 3

overArgFunction · 0.70
overRestFunction · 0.70
overArgFunction · 0.50

Calls 4

getIterateeFunction · 0.85
isObjectFunction · 0.85
isFunctionFunction · 0.85
iterateeFunction · 0.70

Tested by

no test coverage detected