MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / pick

Function pick

MathBox/mathbox-bundle.js:37949–37971  ·  view source on GitHub ↗

* Creates a shallow clone of `object` composed of the specified properties. * Property names may be specified as individual arguments or as arrays of * property names. If a callback is provided it will be executed for each * property of `object` picking the properties the callback ret

(object, callback, thisArg)

Source from the content-addressed store, hash-verified

37947 * // => { 'name': 'fred' }
37948 */
37949 function pick(object, callback, thisArg) {
37950 var result = {};
37951 if (typeof callback != 'function') {
37952 var index = -1,
37953 props = baseFlatten(arguments, true, false, 1),
37954 length = isObject(object) ? props.length : 0;
37955
37956 while (++index < length) {
37957 var key = props[index];
37958 if (key in object) {
37959 result[key] = object[key];
37960 }
37961 }
37962 } else {
37963 callback = lodash.createCallback(callback, thisArg, 3);
37964 forIn(object, function(value, key, object) {
37965 if (callback(value, key, object)) {
37966 result[key] = value;
37967 }
37968 });
37969 }
37970 return result;
37971 }
37972
37973 /**
37974 * An alternative to `_.reduce` this method transforms `object` to a new

Callers

nothing calls this directly

Calls 4

baseFlattenFunction · 0.85
forInFunction · 0.85
isObjectFunction · 0.70
callbackFunction · 0.70

Tested by

no test coverage detected