Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
Created December 29, 2011 04:00
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 mlhaufe/1531772 to your computer and use it in GitHub Desktop.
Save mlhaufe/1531772 to your computer and use it in GitHub Desktop.
JavaScript 1.5 Permutations
var perm = (function(){
function perm(xs, ys, o){
if(ys.length){
for(var i=0,v;(v=xs+ys.charAt(i)),i<ys.length;i++){
o[v] = 1;
perm(v, ys.slice(0,i) + ys.slice(i + 1),o)
}
}
}
return function(ys){
var o = {}, a = []
perm('',ys, o)
for(var i in o)
a[a.length] = i;
return a;
}
})()
var p = perm('abcdef')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment