@jonahsnider/util

    Function allDuplicates

    • Get an array of all the duplicate elements in an iterable.

      Time complexity: O(n)

      Space complexity: O(n)

      Type Parameters

      • T

      Parameters

      • iterable: Iterable<T>

        The iterable to find duplicates in

      Returns T[]

      An array of the duplicated elements

      Iterable

      allDuplicates([1, 2, 2, 2, 3]); // [2, 2]
      

      Using frequencyTable to get the number of times each element was duplicated

      frequencyTable(allDuplicates([1, 2, 2, 2, 3, 3])); // Map(2) { 2 => 2, 3 => 1 }
      

      duplicates to receive a Set of duplicate elements instead of an array (which can include the same element more than once)

    MMNEPVFCICPMFPCPTTAAATR