UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

26 lines (24 loc) 699 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/array/isShallowEqual.ts /** * `isShallowEqual(array, other)` * * Returns `true` if `array` and `other` have the same length and their elements are equal using shallow comparison, otherwise returns `false`. * * ```ts * isShallowEqual([1, 2, 3], [1, 2, 3]); // true * ``` * * ```ts * pipe([1, 2, 3], isShallowEqual([1, 2, 3])); // true * ``` */ const isShallowEqual = dfdlT((a, b) => { if (a === b || Object.is(a, b)) return true; const len = a.length; if (len !== b.length) return false; for (let i = 0; i < len; i++) if (a[i] !== b[i] || !Object.is(a[i], b[i])) return false; return true; }, 2); //#endregion export { isShallowEqual };