(...arrays: Array<T[]>)
| 28 | } |
| 29 | |
| 30 | export function getArraysCommonPart<T extends object>(...arrays: Array<T[]>) { |
| 31 | if (arrays.length === 0) return []; |
| 32 | if (arrays.length === 1) return arrays[0]; |
| 33 | |
| 34 | const fromShortest = sortBy(arrays, (array) => array.length); |
| 35 | |
| 36 | const [first, ...arraysToCheck] = fromShortest; |
| 37 | |
| 38 | const remainingItems = new Set(first); |
| 39 | |
| 40 | for (const nextArray of arraysToCheck) { |
| 41 | for (const remainingItem of remainingItems) { |
| 42 | if (!nextArray.includes(remainingItem)) { |
| 43 | remainingItems.delete(remainingItem); |
| 44 | |
| 45 | if (remainingItems.size === 0) return []; |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | return Array.from(remainingItems); |
| 51 | } |
| 52 | |
| 53 | export function areArraysShallowEqual<T>(a: T[], b: T[]) { |
| 54 | if (a === b) return true; |
no outgoing calls
no test coverage detected