Awesome article. First i am seeing sets. Also glad to read comment below that its runtime is better than expected because to me it is more readable. Also i think allot of the array prototype functions can make the code harder to read in the long run. Assuming you know a bit of background on sets, that last example is so concise!
That being said, could you explain how the ... spread operator works with it? Trying to get my head around that at the moment.
Sets don't come with the same prototype functions as arrays. They have a forEach method, but no map or filter, for example (I think). The spread operator and square braces there are simply extracting the values from the set and turning them into an array.
Thankyou that makes sense. Spread operator has been a tough one to learn for me. I always feel like i kind if have an idea of what it is doing in one situation but struggle to use it myself.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Awesome article. First i am seeing sets. Also glad to read comment below that its runtime is better than expected because to me it is more readable. Also i think allot of the array prototype functions can make the code harder to read in the long run. Assuming you know a bit of background on sets, that last example is so concise!
That being said, could you explain how the ... spread operator works with it? Trying to get my head around that at the moment.
Sets don't come with the same prototype functions as arrays. They have a
forEach
method, but nomap
orfilter
, for example (I think). The spread operator and square braces there are simply extracting the values from the set and turning them into an array.Thanks James!
Because the
Set
object implements the iterator property, we can use the ES6 spread syntax to cast the values from theSet
into an array.It really is doing the same thing as the second part of that example, where I called
Array.from()
.Thankyou that makes sense. Spread operator has been a tough one to learn for me. I always feel like i kind if have an idea of what it is doing in one situation but struggle to use it myself.