Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up`array.indexOf(x, -0)` unnecessarily coerces its start offset to `+0` #1327
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
|
Wouldn't that allow the algorithm to return |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
isiahmeadows
Oct 11, 2018
Good point. You'd have to coerce it in that case, although you could wait until the end to do so. I updated the aside to take that into consideration.
isiahmeadows
commented
Oct 11, 2018
|
Good point. You'd have to coerce it in that case, although you could wait until the end to do so. I updated the aside to take that into consideration. |
isiahmeadows
closed this
Oct 11, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
isiahmeadows commentedOct 11, 2018
•
edited
In step 7.a of
Array.prototype.indexOf's algorithm, it says "If n is -0, let k be +0; else let k be n.". This could be simplified to "Let k be n." just like inArray.prototype.indexOfwithout observable effect, sinceToString(-0)yields"0", not"-0".Also, as an aside, it might be a good idea to fuse steps 6-8 of
Array.prototype.indexOfand steps 6-7 ofArray.prototype.includesinto a shared abstract operation that does basically this and let the case of n = len initially fall out naturally, simplifying the spec text for both operations (and the corresponding typed array operations):CoerceOffsetWithLength(n, len):