Skip to content

Instantly share code, notes, and snippets.

@robertpitt
Created August 1, 2012 04:42
Show Gist options
  • Save robertpitt/3223734 to your computer and use it in GitHub Desktop.
Save robertpitt/3223734 to your computer and use it in GitHub Desktop.
(function(){
/**
* Create the perms stack
*/
var stack = [];
/**
* Declare permute functuin
*/
function permute(pref, str)
{
/**
* Set the string to an empty string of value is of negative.
*/
var prefix = pref || "";
var N = str.length;
/**
* Print out the perm
*/
if(N == 0){
stack.push(prefix)
return;
}
for (var i = 0; i < N; i++)
{
permute(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, N));
}
}
console.time("a");
permute(null, "ABCDEFGHIJKL");
console.timeEnd("a", "Permuted ABCDEF");
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment