jashkenas/underscore

Strange behavior with _.range function

yoander opened this issue · 3 comments

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.

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. ;)