Function duplicates

  • Category

    Get a Set of 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 Set<T>

    A Set of the duplicated elements

    Iterable

    duplicates([1, 2, 2, 2, 3]); // Set(1) { 2 }
    

    allDuplicates to receive a array of duplicate elements instead of a Set (which doesn't include the same element more than once)