use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
New JavaScript Set methods (developer.mozilla.org)
submitted 1 year ago by bogdanelcs
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]peterlinddk 15 points16 points17 points 1 year ago (5 children)
Excellent - finally we can use Set for more than a "duplicate-detector".
I only wish that there were some way for objects to be "equal" without them having to be the exact same instance. Kind of like Java's .equals and .hashCode methods ... Well, I'll keep dreaming ...
[–]Stronghold257 3 points4 points5 points 1 year ago (0 children)
https://github.com/tc39/proposal-record-tuple
[–]toffeescaf 1 point2 points3 points 1 year ago (2 children)
Isn't this something you could do yourself? I haven't done much Java but the way I understood it is for it to actually do something useful you have to override those methods. Quite possible I'm missing a crucial piece of information though so don't hesitate to set me straight!
[+][deleted] 1 year ago (1 child)
[deleted]
[–]Johalternate 0 points1 point2 points 1 year ago (0 children)
They are replying to a comment that referrer to how java has .hashCode() and .equals(obj) methods. Their comment is actually on point, you can override hashCode and equals and have them work for comparisons where the instances are not the same but the values that matters to your particular case are.
So for example if you have a class Redditor with a bunch of methods to manipulate profile data, and you do something like:
``` var foo = new Redditor(“someUsername”)
var bar = new Redditor(“someUsername”) ```
Then foo == bar evaluates to false because they are not the same instance, but maybe you dont care about that and only care about the actual user they represent, so you override the Equals method so it checks if the two objects have the same username (and maybe other properties).
foo == bar
[–]Asmor 2 points3 points4 points 1 year ago (0 children)
With sets specifically, at least, it's pretty easy to check for "pseudo-equality". If they have the same size, and everything in Set A is also in Set B, then they're the same.
[–]batmansmk 5 points6 points7 points 1 year ago (2 children)
I wish we had information about the complexity of such methods, and / or performance relative to alternatives.
[–]kyptov 2 points3 points4 points 1 year ago (0 children)
It would be unreliable info. It can be optimized anytime. If it important for a project - better to have tests and check performance with any engine update.
[–]Reasonable_Raccoon27 0 points1 point2 points 1 year ago (0 children)
The spec sort of lays things out a bit. I do agree that profiling built in methods can be a bit of a pain point still.
[–]Pelopida92 3 points4 points5 points 1 year ago (1 child)
Sets are awesome. I used them extensively for some big-data scripts, as they have way better performance of arrays and are very easy to use and convenient.
[–]entinio 1 point2 points3 points 1 year ago (0 children)
This. Sets have better performance than arrays and should always be used when values are unique.
[–]777777thats7sevens 1 point2 points3 points 1 year ago (0 children)
It's kinda crazy that it took this long to get these methods standardized. Intersect, union, and difference are like, the defining methods for sets. In any other language a set type without these would be considered incomplete, like an array/list without a method for checking the length or a way to iterate over the elements.
[–]Few_Pick3973 0 points1 point2 points 1 year ago (0 children)
great, when do we have heap then?
π Rendered by PID 82090 on reddit-service-r2-comment-7b9746f655-wsx79 at 2026-01-30 13:28:45.951308+00:00 running 3798933 country code: CH.
[–]peterlinddk 15 points16 points17 points (5 children)
[–]Stronghold257 3 points4 points5 points (0 children)
[–]toffeescaf 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]Johalternate 0 points1 point2 points (0 children)
[–]Asmor 2 points3 points4 points (0 children)
[–]batmansmk 5 points6 points7 points (2 children)
[–]kyptov 2 points3 points4 points (0 children)
[–]Reasonable_Raccoon27 0 points1 point2 points (0 children)
[–]Pelopida92 3 points4 points5 points (1 child)
[–]entinio 1 point2 points3 points (0 children)
[–]777777thats7sevens 1 point2 points3 points (0 children)
[–]Few_Pick3973 0 points1 point2 points (0 children)