Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created July 17, 2020 15:24
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 alandipert/19e214ee8d242fa88c835f44d325795e to your computer and use it in GitHub Desktop.
Save alandipert/19e214ee8d242fa88c835f44d325795e to your computer and use it in GitHub Desktop.
const removeAt = (xs, i) => xs.filter((x, j) => j !== i);
const permute = xs => xs.length
? xs.flatMap((x, i) => permute(removeAt(xs, i)).map(ys => [x, ...ys]))
: [[]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment