Skip to content

Instantly share code, notes, and snippets.

@neodigm
Created March 17, 2023 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neodigm/551fd11c2d1d993454768b755c1fee02 to your computer and use it in GitHub Desktop.
Save neodigm/551fd11c2d1d993454768b755c1fee02 to your computer and use it in GitHub Desktop.
// Get all combinations of a multi-select control
const getAllSubsets = aPowerSet => aPowerSet.reduce( (subsets, value) => subsets.concat( subsets.map(set => [value,...set]) ), [[]] );
// usage
getAllSubsets(["sun","mon","tue","wed","thr","fri","sat"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment