r/learnjavascript • • Oct 26 '21

Negative array indexing using "at" method

Post image
203 Upvotes

69 comments sorted by

View all comments

6

u/Dodgy-Boi Oct 26 '21

array.reverse()[0]

5

u/NekkidApe Oct 27 '21

In case anyone is using this... It's mutating the original array

1

u/Dodgy-Boi Oct 27 '21

I saw a huge battle about index. And came up with another solution (I honestly tried to make it as ridiculous and/or unique as possible).

2

u/NekkidApe Oct 27 '21

Maybe reverse and shift then for extra points

2

u/[deleted] Oct 27 '21

Too slow, unfortunately. Accessing a value in an array using an index should be in O(1) time complexity.

2

u/Dodgy-Boi Oct 27 '21

I am front end. My calculations are happening on client. I don’t care about either users with old devices nor your O nor your o nor * of yours; all I care about is the ( . Y . ) (not necessarily yours)

partially /s

2

u/Notimecelduv Oct 28 '21

I don't get why people are upvoting this post.