Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (35 sloc) 769 Bytes

Set

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)),
  };
}

You can’t perform that action at this time.