Other people are giving you good answers, but I'm not sure they're highlighting the important principle, which is:
You're looking for a function that depends on the "order of magnitude" of a given number. Logarithms are probably the easiest way of getting that information.
A log base 10 more or less answers the question "What's the largest power of 10 this number is divisible by?" or "How many times could I divide this number by 10 before it would be less than one?"
You could write a function which answers this question manually, of course:
function divsBy10(n) {
var i = 0;
while(n > 1) {
n = n/10;
i++;
}
return i-1;
}
And the overhead wouldn't be high. I'd guess it's a bit faster to use natively implemented math functions, though. Of course, it doesn't look like you get a native log base 10 in Actionscript... it appears Math.log is a natural log (log base e). There's a mathematical identity which says log_10 x = log_e x / log_e 10 ... and ActionScript does give you a log_e 10 as a constant (Math.LN10). So,
function log10(n) {
return Math.log(n)/Math.LN10;
}
Now, log10 won't yield an integer answer to the questions I mentioned above ("How many times could I divide n by 10 before it's less than 1?"), because it's actually the inverse of 10^n, but the integral portion of the return value will be the answer to that question. So you'd want to do Math.floor on the value you get back from it, and from there, do the various computations you'll need in order to get the specific array ranges you need.