Skip to content

Instantly share code, notes, and snippets.

@Kadajett
Created June 5, 2019 20:52
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 Kadajett/27241817a0a44bc54f1e9b9dca574b2b to your computer and use it in GitHub Desktop.
Save Kadajett/27241817a0a44bc54f1e9b9dca574b2b to your computer and use it in GitHub Desktop.
Function permuteString(input, iter = 0) {
if(iter == input.length - 1) return;
Let currentArr = Array.from(input);
Let firstChar = currentArr[0];
currentArr = currentArr.splice(0,1); edbc
// loop through for all the characters
for(let i = 0; i < currentArr.length; i++) {
Let tempItem = currentArr[i];
currentArr[i] = currentArr[i+1];
currentArr[i+1] = tempItem;
console.log(firstChar, ...currentArr);
}
Let newString = [ currentArr[currentArr.length - 1], ...currentArr.splice(1, currentArr.length - 1)] // this would need to be turned back into a string
iter++;
Return permuteString(newString, iter)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment