MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / transform

Function transform

lib/web/jshint.js:11377–11397  ·  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 * properties through `iteratee`, with each invocation potentially mutating * the `accumulator` object. The `iteratee` is bound to `

(object, iteratee, accumulator, thisArg)

Source from the content-addressed store, hash-verified

11375 * // => { 'a': 3, 'b': 6 }
11376 */
11377 function transform(object, iteratee, accumulator, thisArg) {
11378 var isArr = isArray(object) || isTypedArray(object);
11379 iteratee = getCallback(iteratee, thisArg, 4);
11380
11381 if (accumulator == null) {
11382 if (isArr || isObject(object)) {
11383 var Ctor = object.constructor;
11384 if (isArr) {
11385 accumulator = isArray(object) ? new Ctor : [];
11386 } else {
11387 accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype);
11388 }
11389 } else {
11390 accumulator = {};
11391 }
11392 }
11393 (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
11394 return iteratee(accumulator, value, index, object);
11395 });
11396 return accumulator;
11397 }
11398
11399 /**
11400 * Creates an array of the own enumerable property values of `object`.

Callers

nothing calls this directly

Calls 5

isTypedArrayFunction · 0.85
getCallbackFunction · 0.85
isArrayFunction · 0.70
isObjectFunction · 0.70
isFunctionFunction · 0.70

Tested by

no test coverage detected