@@ 238-247 (lines=10) @@ | ||
235 | }; |
|
236 | ||
237 | // Return the minimum element (or element-based computation). |
|
238 | _.min = function(obj, iterator, context) { |
|
239 | if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj); |
|
240 | if (!iterator && _.isEmpty(obj)) return Infinity; |
|
241 | var result = {computed : Infinity}; |
|
242 | each(obj, function(value, index, list) { |
|
243 | var computed = iterator ? iterator.call(context, value, index, list) : value; |
|
244 | computed < result.computed && (result = {value : value, computed : computed}); |
|
245 | }); |
|
246 | return result.value; |
|
247 | }; |
|
248 | ||
249 | // Shuffle an array. |
|
250 | _.shuffle = function(obj) { |
|
@@ 226-235 (lines=10) @@ | ||
223 | }; |
|
224 | ||
225 | // Return the maximum element or (element-based computation). |
|
226 | _.max = function(obj, iterator, context) { |
|
227 | if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj); |
|
228 | if (!iterator && _.isEmpty(obj)) return -Infinity; |
|
229 | var result = {computed : -Infinity}; |
|
230 | each(obj, function(value, index, list) { |
|
231 | var computed = iterator ? iterator.call(context, value, index, list) : value; |
|
232 | computed >= result.computed && (result = {value : value, computed : computed}); |
|
233 | }); |
|
234 | return result.value; |
|
235 | }; |
|
236 | ||
237 | // Return the minimum element (or element-based computation). |
|
238 | _.min = function(obj, iterator, context) { |