(a: V[], b: V[])
| 38 | } |
| 39 | |
| 40 | export function intersection<V>(a: V[], b: V[]): V[] { |
| 41 | const B = new Set(b); |
| 42 | return [...a].filter(item => B.has(item)); |
| 43 | } |
| 44 | |
| 45 | // arr.filter(x => x !== null) returns a (T | null)[] even though it is a T[] |
| 46 | // Apparently the idiomatic solution is arr.filter((x): x is T => x !== null), but this is shorter (and the type |