I have a scenario in which I have to store a tuple (x,y,z) in a set. As javascript doesn't have a tuple, I decided to store it in the set like [1,2,0], but it allows me to add this same
element again to the set and show the size as 2, whereas ideally, it should not add it. How can I achieve default Set behavior or some alternate way to represent the above information
Asked
Active
Viewed 389 times
0

daniel
- 369
- 2
- 10
-
1consider JSON serialization. – Daniel A. White Nov 02 '21 at 13:20
-
2This may provide a bit of background on why it allows the same tuple value: https://stackoverflow.com/questions/29759480/how-to-customize-object-equality-for-javascript-set – sma Nov 02 '21 at 13:22
-
1Every array is a distinct object from other arrays, even if they contain the exact same contents. The Set mechanism only cares about object identity, not content. – Pointy Nov 02 '21 at 13:23
-
so there is nothing like a set in the same way we have in other languages like python and java – daniel Nov 02 '21 at 14:34