Strange behavior with _.range function #634

yoander opened this Issue Jun 8, 2012 · 3 comments


None yet

2 participants


Some example:
_.range(4) or _range(0, 4) or _.range("4") produce [0, 1, 2, 3] - OK
_.range("0", 4) or _range("0", "4") produce ["0", "01", "011", "0111"] I was expected [0, 1, 2, 3]

from the above examples I've conclude that star parameter is not parse as stop parameter

I tested in iceweasel 10.0.4 / Debian 6.5 with Underscore.js 1.3.3


_.range is defined for numbers, not for strings, I'm afraid. If you pass in other objects as well, it similarly won't work.

@jashkenas jashkenas closed this Jun 8, 2012

Ok, I agree why _.range("4") produce [0, 1, 2, 3] then?


It shouldn't -- ideally it would throw an error. But, this being a dynamic language, we don't hard police the input arguments to every single function. It's entirely possible to pass a function bad values and get strange results. Just don't do it. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment