Created
April 23, 2013 04:02
-
-
Save charlietuna/5440780 to your computer and use it in GitHub Desktop.
Takes a list and returns an array of permutations of that list.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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