Skip to content

Instantly share code, notes, and snippets.

@pinkmomo027
Created June 26, 2018 20:57
Show Gist options
  • Save pinkmomo027/57407d56b982f9698e9edb04d9342b4d to your computer and use it in GitHub Desktop.
Save pinkmomo027/57407d56b982f9698e9edb04d9342b4d to your computer and use it in GitHub Desktop.
permutation
function travel(temp, level) {
if (count.every(element => element == 0) ) {
result.push(temp.join(''));
return;
}
for (let i = 0; i < count.length; i++) {
if (count[i] > 0) {
count[i]--;
temp[level] = chars[i];
travel(temp, level+1);
count[i]++;
}
}
}
travel(temp, level=0);
console.log(result);
@pinkmomo027
Copy link
Author

[ 'AABC',
  'AACB',
  'ABAC',
  'ABCA',
  'ACAB',
  'ACBA',
  'BAAC',
  'BACA',
  'BCAA',
  'CAAB',
  'CABA',
  'CBAA' ]
[Finished in 0.1s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment