Skip to content

Instantly share code, notes, and snippets.

@charlietuna
Created April 23, 2013 04:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save charlietuna/5440780 to your computer and use it in GitHub Desktop.
Takes a list and returns an array of permutations of that list.
permute_list = (list) ->
if list.length <= 1
return [ list ]
permutations = []
for first, i in list
restOfList = list.slice()
restOfList.splice(i, 1)
for subperm in permute_list(restOfList)
permutations.push([ first ].concat(subperm))
return permutations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment