#15 Data Structures with JS examples: Sets - Frontend Weekly - Medium

PHOTO EMBED

Fri May 29 2020 16:14:21 GMT+0000 (Coordinated Universal Time)

Saved by @newborn #javascript

intersection(secondSet) {
  const intersectionSet = new Set()
  const firstSetValues = this.values()
  const secondSetValues = secondSet.values()
  const allValues = [...firstSetValues, ...secondSetValues]
  allValues.forEach(
    value =>
      secondSet.has(value) && 
      this.has(value) && 
      intersectionSet.add(value),
  )
  return intersectionSet
}
content_copyCOPY

https://medium.com/front-end-weekly/15-data-structures-with-js-examples-sets-5c0c7e52203