If you have many time intervals, you can go something like this:
var ranges = [[10, 'large'], [5, 'medium'], [0, 'small']]; function range(n) { for (var i = 0; i < ranges.length; i++) { if (n > ranges[i][0]) { return ranges[i][1]; } } return 'default value'; }
This is not so flexible, since you cannot specify < or <= for each case, but if I had many ranges, I could write something like this. The other answers are great, I just thought I'd add this as an idea.
source share