@trashpanda001/helpers
    Preparing search index...

    Function uniqBy

    • Returns a new array that removes elements for which uniqFn returned duplicate elements.

      The first occurrence of each element is kept.

      Optimized implementation using for...of loop instead of forEach for better performance.

      Type Parameters

      Parameters

      • array: readonly T[]

        the input array

      • uniqFn: (x: T) => S

        a function that returns the value to check for duplicates

      Returns T[]

      a new array with unique elements

      Unique elements by length.

      import { uniqBy } from "@trashpanda001/helpers/array"

      uniqBy(["cat", "dog", "raccoon", "meow", "woof"], (x) => x.length)
      // ["cat", "raccoon", "meow"]