UNPKG

@n3okill/utils

Version:
37 lines 1.31 kB
import { isArrayType } from "../type/isArrayType"; /** * Return the difference between arrays (all the items that appear only once in the first array) * @param arr The first array * @param args Other arrays to compare * @returns The resulting array with the diff items */ export function diff(arr, ...args) { const target = []; const arrLength = arr.length; const argsLength = args.length; for (let i = 0; i < arrLength; i++) { // eslint-disable-next-line security/detect-object-injection const elem = arr[i]; let hasElem = false; for (let j = 0; j < argsLength; j++) { // eslint-disable-next-line security/detect-object-injection const current = args[j]; if (isArrayType(current)) { const curLength = current.length; for (let c = 0; c < curLength; c++) { // eslint-disable-next-line security/detect-object-injection if (elem === current[c]) { hasElem = true; c = curLength; j = argsLength; } } } } if (!hasElem) { target.push(elem); } } return target; } //# sourceMappingURL=diff.js.map