Assert
isUnorderedEqual

🔄 Checks if two arrays are equivalent, regardless of element order.

It performs deep comparisons using the isEql function.

It also supports comparing sparse arrays (opens in a new tab).

Syntax

import { isUnorderedEqual } from '@opentf/std';
 
isUnorderedEqual(arr1: unknown[], arr2: unknown[]): boolean

Parameters

  • arr1: The first array to compare.
  • arr2: The second array to compare.

Returns

true if the arrays contain the same elements in any order, false otherwise.

Examples

isUnorderedEqual([1, 3, 2], [2, 1, 3]) //=> true
 
isUnorderedEqual([1, 3, 2], [2, 1, 5]) //=> false
 
isUnorderedEqual([{ a: 1 }, { b: 2 }], [{ b: 2 }, { a: 1 }]) //=> true

Related

Try