hax / proposal-index-from-end

A JavaScript proposal to add `a[^i]` syntax for `a[a.length - i]`
MIT License
17 stars 0 forks source link

why not `setAt`? #7

Closed michaelficarra closed 9 months ago

michaelficarra commented 10 months ago

You say that this is motivated even in the presence of .at(relativeIndex) because it is also allowed in assignment position. Can't a setAt(relativeIndex, value) also be a solution to this problem?

hax commented 9 months ago

Even have a.setAt(i, v), the ergonomics still can't compare to a[^i] in many cases, for example:

a[^index]++ vs a.setAt(-index, a.at(-index) + 1)

And negative index also have the flaws of -0 edge cases and easy to misuse in the case like let i = a.findIndex(test); a.at(i) (i might be -1)

hax commented 9 months ago

I also presented other reasons why a[^i] is better, you could even check my first time presentation (at that time, at() still not stage 4, so have more details comparison and why at() is not a good thing IMO)

Consider this issue as solved. Feel free to reopen if need any further discussion.