* Retrieves the minimum 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` a
(collection, callback, thisArg)
| 38766 | * // => { 'name': 'barney', 'age': 36 }; |
| 38767 | */ |
| 38768 | function min(collection, callback, thisArg) { |
| 38769 | var computed = Infinity, |
| 38770 | result = computed; |
| 38771 | |
| 38772 | // allows working with functions like `_.map` without using |
| 38773 | // their `index` argument as a callback |
| 38774 | if (typeof callback != 'function' && thisArg && thisArg[callback] === collection) { |
| 38775 | callback = null; |
| 38776 | } |
| 38777 | if (callback == null && isArray(collection)) { |
| 38778 | var index = -1, |
| 38779 | length = collection.length; |
| 38780 | |
| 38781 | while (++index < length) { |
| 38782 | var value = collection[index]; |
| 38783 | if (value < result) { |
| 38784 | result = value; |
| 38785 | } |
| 38786 | } |
| 38787 | } else { |
| 38788 | callback = (callback == null && isString(collection)) |
| 38789 | ? charAtCallback |
| 38790 | : lodash.createCallback(callback, thisArg, 3); |
| 38791 | |
| 38792 | forEach(collection, function(value, index, collection) { |
| 38793 | var current = callback(value, index, collection); |
| 38794 | if (current < computed) { |
| 38795 | computed = current; |
| 38796 | result = value; |
| 38797 | } |
| 38798 | }); |
| 38799 | } |
| 38800 | return result; |
| 38801 | } |
| 38802 | |
| 38803 | /** |
| 38804 | * Retrieves the value of a specified property from all elements in the collection. |