Skip to content

Repository files navigation

@tsdotnet/array-compare: Compare arrays by value. Equal, or equivalent in any order.

npm version GitHub license

Compare two arrays element by element, for equality or for equivalence in any order.

Install

npm install @tsdotnet/array-compare

Usage

import { areEqual, areEquivalent } from '@tsdotnet/array-compare';

areEqual([1, 2, 3], [1, 2, 3]);       // true
areEqual([1, 2, 3], [3, 2, 1]);       // false: order matters
areEquivalent([1, 2, 3], [3, 2, 1]);  // true: same items, any order

Both take an optional comparison for your own item type. areAllEqual checks a whole set of arrays against the first.

Use it from

ESM (import { areEqual, areEquivalent } from '@tsdotnet/array-compare';) or CommonJS (const { areEqual, areEquivalent } = require('@tsdotnet/array-compare');).

In a browser, without a bundler
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/type@1/dist/umd/type.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/compare@1/dist/umd/compare.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/exceptions@1/dist/umd/exceptions.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/array-compare@1/dist/umd/array-compare.min.js"></script>
<script>
  const { areEqual, areEquivalent } = tsdotnet.arrayCompare;
</script>

Docs

tsdotnet.github.io/array-compare

Releases

Packages

Used by

Contributors

Languages