Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

what the '7 more characters' are #38

Open
fayfang opened this issue Dec 6, 2020 · 3 comments
Open

what the '7 more characters' are #38

fayfang opened this issue Dec 6, 2020 · 3 comments

Comments

@fayfang
Copy link

fayfang commented Dec 6, 2020

arr[arr.length - N], where N is the Nth item from the end (starting at 1). This requires naming the indexable twice, additionally adds 7 more characters for the .length

I just notice here 'additionally adds 7 more characters for the .length', and i don't know what the '7 more characters' are.

thanks a lot for any answer.

@Zarel
Copy link

Zarel commented Dec 6, 2020

The 7 more characters in question are .length.

That sentence is just saying that arr[arr.length - N] is a lot longer than arr[-N].

@hax
Copy link
Member

hax commented Dec 31, 2020

Actually if compare to arr.at(-n) it only save 5 more chars. 😂

@sinsys
Copy link

sinsys commented Jan 14, 2021

Have you considered the implications of a nested array though?

let data = [[0,1],[0,1]]
data[data.length - 1]
  [data[data.length - 1].length - 1]

Lots of other approaches too, like scattering variables, or spreading and popping... All of which are pretty ugly.

I'd much prefer....
data[-1][-1]

Or even:.
data.at(-1).at(-1)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants