Created
June 5, 2019 20:52
-
-
Save Kadajett/27241817a0a44bc54f1e9b9dca574b2b to your computer and use it in GitHub Desktop.
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
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