It sounds weird but I need this for now.Actually I have an array like that :
var arr = new Array(123, 432, 98, 227, 764);
var max = Math.max.apply(Math, arr); //calculate max = 764
var min = Math.min.apply(Math, arr); //calculate min = 123
Now I have to make several range based on the min and max:
100 - 200 // as the min is 123 (range 100 ~ 200)
201 - 300
301 - 400
401 - 500
501 - 600
601 - 700
701 - 800 // as the min is 764 (range 700 ~ 800)
Making the range is just a loop issue.But calculating the range of min and max I implemented as :
function integerRound (digit) {
var i = 0, msb;
while( digit > 0 ) {
msb = digit % 10;
digit = Math.floor( digit / 10 );
i++;
}
while ( i > 1 ) {
msb = msb + '0';
i--;
};
return msb;
}
var lowerMin = integerRound(min); // 100
var lowerMax = integerRound(max); // 700
My question is - Is there any good way to do that in javascript or jQuery?