javascript - Getting a portion of a sorted array from start value to end value -


i'm pretty new javascript , need portion (slice) of sorted array (numbers, timestamps basically) start_value , end_value.

for example, let's have array of random timestamps last month, , want timestamps between 2 weeks ago , week ago. pretty simple algorithm write (using binary search) don't want mess code these computations. i've been searching way in javascript haven't found any.

thanks future :)

perhaps use filter?

var dates = [123, 234, 456, 468, 568, 678];  var min = 300;  var max = 500;    var inrange = dates.filter(function(date) {      return min < date && date < max;  });    console.log(inrange);

on plus side, doesn't need them sorted. on down side, won't fast well-implemented binary search relevant start , end points. unless you've got harsh performance requirements don't think that'll matter.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -