javascript - Sample array at even intervals -


i have array size , i'm interested in fixed number of elements, evenly distributed. want 1000 elements. if there 1000 or less elements in array, want them all, that's easy. if there 2000 elements in array, want every second one. 3000 elements , i'd want every third one... , on.

i'm having trouble implementing this. thought of using modulo , works round numbers. e.g. 2000 / 1000 = 2 simple if (n % 2 == 0) works here (so skip each element evaluates true). likewise 1200: excess 200 1200 / 200 = 6 if (n % 6 == 0) works.

however, breaks down when number of elements divided excess isn't nice round number:

elements = 2788
limit = 1000
factor = 2788 / (2788 - 1000) = 1.559288

here modulo operator won't work n % 1.55928 never going give remainder of zero. know how achieve this? i'm using javascript. thanks!

what want uniform discrete distribution. because number of elements not divisible limit, want flexibility in limit keep evenly distributed. so, perform sampling in elements/limit intervals, rounding result nearest integer.

if limit flexible , can cover more ground finding biggest possible limit (in case, 697).


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -