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

[Proposition] Array.get, Array.set support negative indices (element from end) #366

Closed
sindikat opened this Issue Aug 23, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@sindikat

sindikat commented Aug 23, 2015

In Python negative list index allows to get or set element from end of the list:

>>> xs = range(0,5)
>>> xs[-1]
4
>>> xs[-1] = 10
>>> xs
[0, 1, 2, 3, 10]

JavaScript, though, doesn't support negative indexes for its Arrays.

I think it makes sense to make Array support negative indexes, after all Array.slice supports them, and Arrays have different semantics from Lists (which are supposed to be traversed once from beginning to end, not sliced constantly). It makes even more sense in 2D games, where you have Matrix a as alias for Array (Array a), so you constantly need to slice a rectangular piece from a huge Matrix and then transform it using your view function to present on screen.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 23, 2015

Member

Seems reasonable, adding to meta issue #322

If you want it in the meantime, do this.

Member

evancz commented Aug 23, 2015

Seems reasonable, adding to meta issue #322

If you want it in the meantime, do this.

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