TS-Scribe - v0.6.2
    Preparing search index...

    Function arrayPowerset

    • Generates the powerset (all subsets) of a given array.

      The powerset includes all subsets of the array, including the empty set. By default, the empty set is excluded, but you can control this behavior with the ignoreEmpty parameter.

      Type Parameters

      • T

      Parameters

      • array: T[]

        The input array for which the powerset is to be generated.

      • ignoreEmpty: boolean = true

        A flag that controls whether the empty subset is included in the result. Default is true (exclude empty set).

      Returns T[][]

      An array of arrays representing all subsets of the input array.

      const result = arrayPowerset([1, 2, 3]);
      console.log(result);
      // Output: [ [ 1 ], [ 2 ], [ 3 ], [ 1, 2 ], [ 1, 3 ], [ 2, 3 ], [ 1, 2, 3 ] ]

      const resultWithEmpty = arrayPowerset([1, 2, 3], false);
      console.log(resultWithEmpty);
      // Output: [ [], [ 1 ], [ 2 ], [ 3 ], [ 1, 2 ], [ 1, 3 ], [ 2, 3 ], [ 1, 2, 3 ] ]