Set

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

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

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

Array.from(new Set())

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

Last modified 3yr ago
Copy link
On this page
Notes:
Set Cloning
Set Iteration
To Array
Differences