Function unique

Combines the values of one or more arrays, removing duplicates

const v = Arrays.unique([ [1, 2, 3, 4], [ 3, 4, 5, 6] ]);
// [ 1, 2, 3, 4, 5, 6]

A single array can be provided as well:

const v = Arrays.unique([ 1, 2, 3, 1, 2, 3 ]);
// [ 1, 2, 3 ]

By default uses JSON.toString() to compare values.

See also:

  • intersection: Overlap between two arrays
  • additionalValues: Yield values from an iterable not present in the other
  • containsDuplicateValues: Returns true if array contains duplicates
  • Type Parameters

    • V

    Parameters

    • arrays:
          | V[]
          | V[][]
          | readonly V[]
          | readonly (readonly V[])[]
    • comparer: ((a: V, b: V) => boolean) = ...
        • (a, b): boolean
        • Default comparer function is equiv to checking a === b. Use isEqualValueDefault to compare by value, via comparing JSON string representation.

          Parameters

          Returns boolean

    Returns readonly V[]