ixfx
    Preparing search index...

    Function unique

    Combines the values of one or more arrays, removing duplicates.

    By default compares values based on a JSON string representation.

    Array (or array of arrays) to examine

    Function to convert values to a string for comparison purposes. By default uses JSON formatting.

    • Combines the values of one or more arrays, removing duplicates.

      const eq = (a, b) => {
      return a.name === b.name
      }
      const v = Arrays.unique([
      [ {name:'jane'}, {name:'billy'}, {name:'thom'} ],
      [ {name:'molly'}, {name:'jane'}, {name:'sally'}, {name:'thom'}]
      ], eq);
      // [ {name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'molly'}, , {name:'sally'} ]

      A single array can be provided as well:

      const v = Arrays.unique([ 
      {name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'billy'},
      ], eq);
      // [ {name:'jane'}, {name:'billy'}, {name:'thom'} ]

      See also:

      • intersection: Get overlap between two arrays
      • Iterables.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: IsEqual<V>

      Returns V[]

    • Combines the values of one or more arrays, removing duplicates.

      Compares based on a string representation of object. Uses a Set to avoid unnecessary comparisons, perhaps faster than using a comparer function.

      const str = (v) => JSON.stringify(v);
      const v = Arrays.unique([
      [ {name:'jane'}, {name:'billy'}, {name:'thom'} ],
      [ {name:'molly'}, {name:'jane'}, {name:'sally'}, {name:'thom'}]
      ], str);
      // [ {name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'molly'}, , {name:'sally'} ]

      A single array can be provided as well:

      const v = Arrays.unique([ 
      {name:'jane'}, {name:'billy'}, {name:'thom'}, {name:'billy'},
      ], eq);
      // [ {name:'jane'}, {name:'billy'}, {name:'thom'} ]

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

      See also:

      • intersection: Overlap between two arrays
      • Iterables.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[])[]

        Array (or array of arrays) to examine

      • toString: (item: V) => string

        Function to convert values to a string for comparison purposes. By default uses JSON formatting.

      Returns V[]

    • Combines the values of one or more arrays, removing duplicates.

      By default compares values based on a JSON string representation.

      Type Parameters

      • V

      Parameters

      • arrays: V[] | V[][] | readonly V[] | readonly (readonly V[])[]

        Array (or array of arrays) to examine

      Returns V[]