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[Proposition] Array.get, Array.set support negative indices (element from end) #366
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
evancz
closed this
Aug 23, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sindikat commentedAug 23, 2015
In Python negative list index allows to get or set element from end of the list:
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 aas alias forArray (Array a), so you constantly need to slice a rectangular piece from a huge Matrix and then transform it using yourviewfunction to present on screen.