@DasSurma (wonder if you might wanna help answer this question) Why did TC39 decide to not give new Map() indexes? https://stackoverflow.com/questions/37822141/how-do-you-get-the-key-at-specifc-index-in-javascript-map-object … Right now we have to loop through the Map to get the index of a key.
If ordering matters, then maps or sets are conceptually the wrong data structure. My mental model is that maps contain a pile of key/value pairs, and sets contain a pile of values. This is also why maps/sets get a `size` rather than a `length`. Length implies an inherent order.
-
-
Length implies an array-like with indexes and triggers array-like code-paths. Sets/maps don't have indexes, hence `size`. Generally I agree with you, but if you need O(1) lookup and ordering, using a set instead of both a set and an array seems OK to me.
-
Sets aren’t ordered though... I’m looking for a key-value primitive that is ordered & indexed lol. Arrays, Objects, Maps & Sets all fail to meet that. Sets aren’t ordered & will need 2 b sorted into an Array. An Array isn’t a key-value data structure and reqs loops for searching.
- 3 more replies
New conversation -
-
-
While this may be true in general of maps/sets, it's not right for JS Maps/Sets. They work great when ordering matters. And the mental model should be an ordered list of pairs, not a pile.
-
Interesting. Something we should be more explicit/vocal about imo. When I hear Set/Map, I don’t assume ordering.
- 4 more replies
New conversation -
-
-
I'd agree with this except there's no OrderedSet or OrderedMap native alternative, except the native structures… which are already ordered. const OrderedSet = Set
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.