UNPKG

@qntm-code/utils

Version:

A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.

19 lines (18 loc) 724 B
import { isEqual } from '../index.js'; /** * Creates an array of array values not included in the other given array using isEqual for equality comparisons. The order and references * of result values are determined by the first array. */ export function difference(array, values) { if (!array.length || !values.length) { return []; } return array.reduce((result, item) => { if (!values.some(value => isEqual(item, value))) { // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call result.push(item); } // eslint-disable-next-line @typescript-eslint/no-unsafe-return return result; }, []); }