Function uniqWith

  • Returns a new array containing only the unique elements from the original array, based on the values returned by the comparator function.

    Type Parameters

    • T

      The type of elements in the array.

    Parameters

    • arr: readonly T[]

      The array to process.

    • areItemsEqual: ((item1: T, item2: T) => boolean)

      The function used to compare the array elements.

        • (item1, item2): boolean
        • Parameters

          • item1: T
          • item2: T

          Returns boolean

    Returns T[]

    A new array containing only the unique elements from the original array, based on the values returned by the comparator function.

    uniqWith([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], (a, b) => Math.abs(a - b) < 1);
    // [1.2, 3.2, 5.7, 7.19]