I’m probably going about this in entirely the wrong way, but pseudocode-wise, this is what I’d like to do:
ranges = new Array([0 - 400] = 'dog',
[401 - 1000] = 'cat',
[1001 - 1233] = 'rat');
alert(ranges[243]);
and magically get ‘dog’ pop up on my screen. Now, I’m well aware you can’t do something that simple, but I have absolutely no idea how to do something like this (without looping through an array, performing a > and < on a value etc..)
Any ideas? 🙂
This one is very simple and straightforward – though it assumes that you don’t want “holes” in your ranges. No error handling in this example, but essentially you just need to pass upper bounds, lower bounds are implicit.