118
Array methods (lemmy.world)
all 10 comments
sorted by: hot top controversial new old
[-] swnt@feddit.de 52 points 1 year ago

While the idea and visualisation is indeed good, there is an error in the visualization.

Namely, the meaning of "->" is inconsistent. IMO it should be the return value of the function call (like in reverse), but for at least pop, the visualization shows the array instead of the array + return value.

For pop the return value isn't the array itself, but the popped value: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop

The visualisation could be improved by clarifying, that the array after the function call is visualised. And using -> isn't the best option IMO, because people expect the right side to contain the return value.

[-] Pyro@programming.dev 14 points 1 year ago

I agree, there should be a distinction between return value and array state.

[-] lily@shinobu.cloud 26 points 1 year ago

map should probably be blueArr.map(blue => purple) instead of blueArr.map(blue => blue = purple)

[-] dingleberry@discuss.tchncs.de 14 points 1 year ago* (last edited 1 year ago)

This would've been much easier to read with plain numbers. Also, easier to read for color blind people.

[1, 2, 3, 4].push(5)             => [1, 2, 3, 4, 5]
[1, 2, 3, 4].unshift(5)          => [5, 1, 2, 3, 4]
[1, 2, 3, 4].pop()               => [1, 2, 3]
[1, 2, 3, 4].shift()             => [2, 3, 4]
[1, 2, 3, 4].map(x => x = 5)     => [5, 5, 5, 5]
[1, 2, 1, 4].filter(x => x == 1) => [1, 1]
[1, 2, 3, 4].reverse()           => [4, 3, 2, 1]
[1, 2, 3, 4].at(2)               => 3
[1, 2, 3, 4].slice(2)            => [3, 4]
[-] tst123@lemmy.world 2 points 1 year ago

Feel free to upload it here when you finish making it

[-] tsonfeir@lemm.ee 12 points 1 year ago

Does anyone else dislike the words shift and unshift for that functionality?

[-] Xanvial@lemmy.world 7 points 1 year ago

Yeah, I really like what Redis do with their commands, LPush LPop RPush RPop, are really straight forward and immediately know what they do

[-] tsonfeir@lemm.ee 2 points 1 year ago

Yes that’s a lot more specific.

[-] SzethFriendOfNimi@lemmy.world 9 points 1 year ago

Like how the colored shapes make what’s happening clearer.

this post was submitted on 26 Sep 2023
118 points (88.3% liked)

JavaScript

1700 readers
1 users here now

founded 1 year ago
MODERATORS