Function combinations

  • Get all possible combinations of elements in a set.

    Examples:

    combinations([1, 2, 3])  // [[1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]
    combinations([1]) // [[1]]

    Type Parameters

    • T

    Parameters

    • set: T[]

      Array of objects of any type. They are treated as unique.

    Returns T[][]

    Array of arrays representing all possible non-empty combinations of elements in a set.