import { curryN } from "@unboxing/function"; import { indexOf } from "./indexOf"; interface Intersection { (list1: ArrayLike, list2: ArrayLike): T[]; (list1: ArrayLike): (list2: ArrayLike) => T[]; } /** * Combines two array into a set (i.e. no duplicates) composed of those * elements common to both arrays. */ export const intersection = curryN(2, (a: ArrayLike = [], b: ArrayLike = []) => { const result = []; for (let i = 0; i < a.length; i++) { if (indexOf(a[i], b) >= 0) { result.push(a[i]); } } return result; }) as Intersection