MCPcopy
hub / github.com/stemkoski/stemkoski.github.com / max

Function max

MathBox/mathbox-bundle.js:38693–38726  ·  view source on GitHub ↗

* Retrieves the maximum value of a collection. If the collection is empty or * falsey `-Infinity` is returned. If a callback is provided it will be executed * for each value in the collection to generate the criterion by which the value * is ranked. The callback is bound to `thisArg`

(collection, callback, thisArg)

Source from the content-addressed store, hash-verified

38691 * // => { 'name': 'fred', 'age': 40 };
38692 */
38693 function max(collection, callback, thisArg) {
38694 var computed = -Infinity,
38695 result = computed;
38696
38697 // allows working with functions like `_.map` without using
38698 // their `index` argument as a callback
38699 if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) {
38700 callback = null;
38701 }
38702 if (callback == null && isArray(collection)) {
38703 var index = -1,
38704 length = collection.length;
38705
38706 while (++index < length) {
38707 var value = collection[index];
38708 if (value > result) {
38709 result = value;
38710 }
38711 }
38712 } else {
38713 callback = (callback == null && isString(collection))
38714 ? charAtCallback
38715 : lodash.createCallback(callback, thisArg, 3);
38716
38717 forEach(collection, function(value, index, collection) {
38718 var current = callback(value, index, collection);
38719 if (current > computed) {
38720 computed = current;
38721 result = value;
38722 }
38723 });
38724 }
38725 return result;
38726 }
38727
38728 /**
38729 * Retrieves the minimum value of a collection. If the collection is empty or

Callers 2

zipFunction · 0.85
jquery-ui.jsFile · 0.85

Calls 4

isStringFunction · 0.85
isArrayFunction · 0.70
forEachFunction · 0.70
callbackFunction · 0.70

Tested by

no test coverage detected