Set

Notes:

    Use Set.add vs Map.set
    Use Set.size vs Array.length
    To remove/delete: use delete

Set Cloning

1
const new = new Set(old);
Copied!
Or if enabled:
1
const new = ...old
Copied!

Set Iteration

1
for (let value of set.values()) {
2
...
3
}
Copied!

To Array

1
Array.from(new Set())
Copied!

Differences

1
function setMath<T>(a: Set<T>, b: Set<T>) {
2
return {
3
remove: [...a].filter(x => !b.has(x)),
4
add: [...b].filter(x => !a.has(x)),
5
};
6
}
Copied!

Last modified 2yr ago