I have an array sorted in ascending order in java script which contains dates in milliseconds.
// Sample data; This may grow upto 1k or 2k
var dates = [1333391400000,1335292200000,1335810600000,1336329000000,1336933800000,1337020200000,
1337193000000,1337538600000,1337625000000,1337797800000,1338316200000,1338921000000,
1339093800000,1339439400000,1340303400000,1341772200000,1342463400000,1343068200000];
I don't have start and end index. I have values. I need to get all dates between 2 dates (Min and Max) from the java script array. I am getting this array from Java through JSON.
Here is the method to get dates between min and max:
function getDatesBetweenRange(min,max){
var subArray = [];
var value, jCntr=0;
for(var iCntr=0;iCntr<dates.length;iCntr++){
value = dates[iCntr];
if(value>max)
break;
if(value >=min && value <=max){
subArray[jCntr++]= value;
}
}
return subArray;
}
As array is in ascending sorted order; I am breaking loop if I get max value than the provided max value in the argument.
Is there any other efficient way to get values from Java Script array ?