I'm currently tackling a challenging problem on Codewars.
Objective
Your goal in this Kata is to develop a function that transforms a string into a Mexican Wave. The output should be an array where each uppercase letter represents a person standing up.
Guidelines
- The input string will always be in lowercase, but it may be empty.
- If the character in the string is whitespace, treat it as an empty seat. Example wave("hello") => ["Hello", "hEllo", "heLlo", "helLo", "hellO"]
Click here to view my current code on repl.it
This is my thought process:
- Convert argument into an array
- Modify each index of the array accordingly to create a wave pattern
- Transform the array back into a string
- Add spaces before logging to the console and then repeat the loop
I am struggling with figuring out how to use
for(var j = 0; j < indexSpaceNumber.length; j++){
//join and add in the spaces at their former index before returning string
strToArray[indexSpaceNumber[j]].slice(0, " ");
}
To correctly insert spaces into the string.
Any guidance or tips would be greatly appreciated. I feel like I am so close, yet also frustratingly far from solving this.