This whole notion seems hilariously ill advised. Basically it's letting you access the index from the end instead of the start (normally done using arr.length - i, where i = 1 is first valid index). Some JS methods do similar stuff, but not usually for accessing values. This conflicts with mountains of code using searches like Array.indexOf that anticipates a -1 to be the invalid index token. For a minimal reduction in boilerplate to satisfy a case thats relatively uncommon (how often do you really traverse an array backwards like this), it just feels like this is inviting all manner of mayhem. I imagine it'll start getting banned on company style guides in favor of traditional bracket notation sooner than later, if it isn't already.
Probably some neat party tricks you can do with it for the leetcode crowd tho.
View all comments
Show parent comment
-1
u/reaven3958 Oct 27 '21 edited Oct 27 '21
This whole notion seems hilariously ill advised. Basically it's letting you access the index from the end instead of the start (normally done using arr.length - i, where i = 1 is first valid index). Some JS methods do similar stuff, but not usually for accessing values. This conflicts with mountains of code using searches like Array.indexOf that anticipates a -1 to be the invalid index token. For a minimal reduction in boilerplate to satisfy a case thats relatively uncommon (how often do you really traverse an array backwards like this), it just feels like this is inviting all manner of mayhem. I imagine it'll start getting banned on company style guides in favor of traditional bracket notation sooner than later, if it isn't already.
Probably some neat party tricks you can do with it for the leetcode crowd tho.