Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active May 25, 2021 12:12
Show Gist options
  • Save rpivo/8524c6ba333c54c7a75f7a809fecaf55 to your computer and use it in GitHub Desktop.
Save rpivo/8524c6ba333c54c7a75f7a809fecaf55 to your computer and use it in GitHub Desktop.
Getting the Number of Subsets Within a Set

Getting the Number of Subsets Within a Set

The number of subsets within a set will always be 2 ^ N, where N is the length of the set.

const a = [1, 2, 3];

console.log(2 ** 3); // 8

Below is the **power set** of the set `a`, or a representation of all the subsets with the set `a`.

/**
 * []
 * [1]
 * [2]
 * [3]
 * [1, 2]
 * [1, 3]
 * [2, 3]
 * [1, 2, 3]
 */

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment