10000 _.range & _.rangeRight behavior for step=0 not explained in documentation · Issue #5944 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

_.range & _.rangeRight behavior for step=0 not explained in documentation #5944

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

Open
emiliodacosta opened this issue Nov 27, 2024 · 0 comments

Comments

@emiliodacosta
Copy link

Regarding expected behavior when step=0, the documentation shows the following for _.range and _.rangeRight :

_.range(1, 4, 0);
// => [1, 1, 1]

_.rangeRight(1, 4, 0);
// => [1, 1, 1]

However, it doesn't include any verbal explanation or code examples demonstrating expected behavior when given an input with start > end and step = 0.

Accordingly, my initial expectation was that the following 4 invocations of both _.range and _.rangeRight would each result in the following identical outputs:

[-4, -4]
[-2, -2]
[2, 2]
[4, 4]

Instead, the actual behavior is the following:

_.range(-4, -2, 0);
// => [-4, -4]
_.range(-2, -4, 0);
// => []
_.range(2, 4, 0);
// => [2, 2]
_.range(4, 2, 0);
// => []

_.rangeRight(-4, -2, 0);
// => [-4, -4]
_.rangeRight(-2, -4, 0);
// => []
_.rangeRight(2, 4, 0);
// => [2, 2]
_.rangeRight(4, 2, 0);
// => []

Apparently, I seem to have proven that the expected output for both _.range and _.rangeRight is [] whenever start > end and step = 0.

It would be nice if this were explained and/or demonstrated in the documentation so that, going forward, individuals like myself wouldn't have to investigate the ambiguity of these two otherwise very useful methods in an otherwise very well-documented library.

Thank you!

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

No branches or pull requests

1 participant
0