Great article!
I love how you mentioned the arr.length = 0;, I've seen obj.arr = []; so many times, messing up references is just a matter of time with the latter.
A nice addition would be to change the 8. Find the intersection of two arrays to do it the other way around as Array.prototype.includes is linear and Set.prototype.has is constant, for larger lists a big difference can be noticed:
let firstValues = [...new Set(numOne)];
let duplicatedValues = numTwo.filter(item => firstValues.has(item));
instead of:
var duplicatedValues = […new Set(numOne)].filter(item => numTwo.includes(item));
Great article!
I love how you mentioned the
arr.length = 0;
, I've seenobj.arr = [];
so many times, messing up references is just a matter of time with the latter.A nice addition would be to change the
8. Find the intersection of two arrays
to do it the other way around asArray.prototype.includes
is linear andSet.prototype.has
is constant, for larger lists a big difference can be noticed:instead of:
You spread Set into an array, so array won't have
has
method on it. Small bug on your side.Oh you're right, first line should have been:
Thanks for pointing that up
to solve this we need either to create second
Set
or to useincludes
instead ofhas