Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior with _.range function #634

Closed
yoander opened this issue Jun 8, 2012 · 3 comments
Closed

Strange behavior with _.range function #634

yoander opened this issue Jun 8, 2012 · 3 comments
Labels

Comments

@yoander
Copy link

yoander commented Jun 8, 2012

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

@jashkenas
Copy link
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.

@yoander
Copy link
Author

yoander commented Jun 8, 2012

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

@jashkenas
Copy link
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
Labels
Projects
None yet
Development

No branches or pull requests

2 participants