Skip to content
This repository

Strange behavior with _.range function #634

Closed
yoander opened this Issue June 08, 2012 · 3 comments

2 participants

Yoander Valdés Rodríguez Jeremy Ashkenas
Yoander Valdés Rodríguez

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

Jeremy Ashkenas
Owner

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

Jeremy Ashkenas jashkenas closed this June 08, 2012
Yoander Valdés Rodríguez

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

Jeremy Ashkenas
Owner

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
Something went wrong with that request. Please try again.