Created
May 11, 2015 04:17
-
-
Save hashrock/daff7128cb354bb3da58 to your computer and use it in GitHub Desktop.
permutation
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
// pure js version of http://qiita.com/higuma/items/5af4e62bdf4df42ce673 | |
function perm(result, l, r, n){ | |
if(n > 0){ | |
r.forEach(function(item, i){ | |
var rest = r.slice(0); | |
var e = rest.splice(i, 1); | |
perm(result, l.concat(e), rest, n - 1); | |
}) | |
}else{ | |
result.push(l); | |
} | |
} | |
function perm2(list){ | |
var result = []; | |
perm(result, [], list, list.length); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment