@@ 281-319 (lines=39) @@ | ||
278 | return small; |
|
279 | }, |
|
280 | ||
281 | indexOfMin: function(start=0, end=-1) { |
|
282 | var vals = this; |
|
283 | ||
284 | // exit quickly if few items .. and checking full array |
|
285 | var len = vals.length; |
|
286 | if (end === -1) { |
|
287 | end = len - 1; |
|
288 | } |
|
289 | if (len === 0 || start > end) { |
|
290 | return -1; |
|
291 | } |
|
292 | ||
293 | // check all values |
|
294 | var small = Number.POSITIVE_INFINITY; |
|
295 | var slot = -1; |
|
296 | var found = 0; |
|
297 | for (var i = start; i <= end; i++) { |
|
298 | ||
299 | // skip nulls |
|
300 | var val = vals[i]; |
|
301 | if (val != null){ |
|
302 | found++; |
|
303 | var num = val; |
|
304 | if (num < small) { |
|
305 | small = num; |
|
306 | slot = i; |
|
307 | } |
|
308 | } |
|
309 | ||
310 | } |
|
311 | ||
312 | // exit if no non-null values found |
|
313 | if (found === 0) { |
|
314 | return -1; |
|
315 | } |
|
316 | ||
317 | // return calculated min value |
|
318 | return slot; |
|
319 | }, |
|
320 | ||
321 | avg: function(start=0, end=-1) { |
|
322 | var vals = this; |
|
@@ 243-279 (lines=37) @@ | ||
240 | return slot; |
|
241 | }, |
|
242 | ||
243 | min: function(start=0, end=-1) { |
|
244 | var vals = this; |
|
245 | ||
246 | // exit quickly if few items .. and checking full array |
|
247 | var len = vals.length; |
|
248 | if (end === -1) { |
|
249 | end = len - 1; |
|
250 | } |
|
251 | if (len === 0 || start > end) { |
|
252 | return 0; |
|
253 | } |
|
254 | ||
255 | // check all values |
|
256 | var small = Number.POSITIVE_INFINITY; |
|
257 | var found = 0; |
|
258 | for (var i = start; i <= end; i++) { |
|
259 | ||
260 | // skip nulls |
|
261 | var val = vals[i]; |
|
262 | if (val != null){ |
|
263 | found++; |
|
264 | var num = val; |
|
265 | if (num < small) { |
|
266 | small = num; |
|
267 | } |
|
268 | } |
|
269 | ||
270 | } |
|
271 | ||
272 | // exit if no non-null values found |
|
273 | if (found === 0) { |
|
274 | return 0; |
|
275 | } |
|
276 | ||
277 | // return calculated min value |
|
278 | return small; |
|
279 | }, |
|
280 | ||
281 | indexOfMin: function(start=0, end=-1) { |
|
282 | var vals = this; |