0 points

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


dashboard

Fri May 29 2020 16:14:21 GMT+0000 (UTC)

Posted 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_copy Copy

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