Skip to content

Instantly share code, notes, and snippets.

@sudodoki
Created December 23, 2016 13:06
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 sudodoki/3013693ff664f49fc69d0cf919f408a1 to your computer and use it in GitHub Desktop.
Save sudodoki/3013693ff664f49fc69d0cf919f408a1 to your computer and use it in GitHub Desktop.
const subsets = ([first, ...rest]) =>
first
? subsets(rest)
.concat(subsets(rest).map(subset => subset.concat(first)))
: [[]]
console.log(JSON.stringify(subsets([1, 2, 3])))
; [[],[3],[2],[3,2],[1],[3,1],[2,1],[3,2,1]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment