Software developer with interest in all parts of CS, specially into UI and ML at the moment.
Outside of CS I am total outdoor person and currently i am trying to learn piano and german.
I'd imagine if you were using a Set from the start, and adding values via the .add method on the Set object, you wouldn't need to store or iterate through the all the duplicates. That won't help if you needed to retain all the dupe data for some other uses though.
I agree that in some use cases you can't use Set. Actually, in some cases, you can't even use it from the beginning, As an example, if you want to have a collection of unique objects, Set won't help.
Software developer with interest in all parts of CS, specially into UI and ML at the moment.
Outside of CS I am total outdoor person and currently i am trying to learn piano and german.
There is a topic on the StackOverflow showing the set is faster. I do personally like filter more, but in most cases, you won't see the difference, and you can go for what looks best in your code.
Software developer with interest in all parts of CS, specially into UI and ML at the moment.
Outside of CS I am total outdoor person and currently i am trying to learn piano and german.
You could sort the array first and then all duplicates will be next to each other:
why did you use an instance of the numbers array, not the number array itself? " [...numbers].sort() not numbers.sort() "
That is a good question, sort is a destructive function. This means running sort on numbers array will change original numbers array.
wow I forgot that
Great ways but is it efficient to use the sets method? Especially in the big arrays.
I'd imagine if you were using a
Setfrom the start, and adding values via the.addmethod on theSetobject, you wouldn't need to store or iterate through the all the duplicates. That won't help if you needed to retain all the dupe data for some other uses though.I agree that in some use cases you can't use
Set. Actually, in some cases, you can't even use it from the beginning, As an example, if you want to have a collection of unique objects,Setwon't help.There is a topic on the StackOverflow showing the set is faster. I do personally like filter more, but in most cases, you won't see the difference, and you can go for what looks best in your code.
That's good. Thanks.
and,, you can create a funtion for it,,
Ah yes, spread operator, love that one :smilery: