@@ 360-381 (lines=22) @@ | ||
357 | return arr[start + index]; |
|
358 | }, |
|
359 | ||
360 | indexOfNearest: function(value, start=0, end=-1) { |
|
361 | var arr = this; |
|
362 | ||
363 | // quickly exit if few values |
|
364 | if (arr.length === 0) { |
|
365 | return -1; |
|
366 | } |
|
367 | if (arr.length === 1) { |
|
368 | return 0; |
|
369 | } |
|
370 | ||
371 | // returns the index of the nearest value |
|
372 | var dists = []; |
|
373 | if (end === -1) { |
|
374 | end = arr.length - 1; |
|
375 | } |
|
376 | for (var a = start; a <= end; a++) { |
|
377 | dists.push(arr[a].distance(value)); |
|
378 | } |
|
379 | var index = dists.indexOfMin(); |
|
380 | return (start + index); |
|
381 | }, |
|
382 | ||
383 | height: function(start=0, end=-1) { |
|
384 | var arr = this; |
|
@@ 337-358 (lines=22) @@ | ||
334 | return vals.total(start, end) / ((end - start)+1); |
|
335 | }, |
|
336 | ||
337 | nearest: function(value, start=0, end=-1) { |
|
338 | var arr = this; |
|
339 | ||
340 | // quickly exit if few values |
|
341 | if (arr.length === 0) { |
|
342 | return value; |
|
343 | } |
|
344 | if (arr.length === 1) { |
|
345 | return arr[0]; |
|
346 | } |
|
347 | ||
348 | // returns the nearest value |
|
349 | var dists = []; |
|
350 | if (end === -1) { |
|
351 | end = arr.length - 1; |
|
352 | } |
|
353 | for (var a = start; a <= end; a++) { |
|
354 | dists.push(arr[a].distance(value)); |
|
355 | } |
|
356 | var index = dists.indexOfMin(); |
|
357 | return arr[start + index]; |
|
358 | }, |
|
359 | ||
360 | indexOfNearest: function(value, start=0, end=-1) { |
|
361 | var arr = this; |