Set

Last updated 5 days ago

Notes:

  • Use Set.add vs Map.set

  • Use Set.size vs Array.length

  • To remove/delete: use delete

Set Cloning

const new = new Set(old);

Or if enabled:

const new = ...old

Set Iteration

for (let value of set.values()) {
...
}

To Array

Array.from(new Set())

Differences

https://github.com/aizatto/nodejs/blob/master/src/fn.js#L42

function setMath<T>(a: Set<T>, b: Set<T>) {
return {
remove: [...a].filter(x => !b.has(x)),
add: [...b].filter(x => !a.has(x)),
};
}