Raw
1 type ArrayIntersectionElement = string | number
2
3 export function arrayIntersection<TElement = ArrayIntersectionElement>(
4 firstArray: TElement[],
5 secondArray: TElement[]
6 ): TElement[] {
7 const firstArraySet = new Set(firstArray)
8 const res = new Set<TElement>()
9
10 secondArray.forEach((element) => {
11 if (firstArraySet.has(element)) {
12 res.add(element)
13 }
14 })
15
16 return Array.from(res)
17 }