Input
A non-empty shuffled string consisting of ASCII characters in the range \$[32..126]\$.
Output
The output is obtained by applying successive rotations to the input string.
For each letter ([a-zA-Z]
) in the input string, going from left to right:
- if the letter is in upper case, rotate all characters before it by one position to the left
- if the letter is in lower case, rotate all characters before it by one position to the right
Example
Input: "Cb-Ad"
- The first letter is a "C". We should do a rotation to the left, but there's no character before this "C". So, there's nothing to rotate.
- The next letter is a "b". We rotate "C" to the right. Because it's a single character, it is left unchanged.
- The character "-" does not trigger any rotation, as it's not a letter.
- The next letter is a "A". We rotate "Cb-" to the left, which gives "b-CAd"
- The fourth and last letter is a "d". We rotate "b-CA" to the right, which gives "Ab-Cd"
Therefore, the expected output is "Ab-Cd".
Rules
- You may take input as a string or as an array of characters -- which may or may not be the same thing, depending on your language.
- You may also output an array of characters instead of a string.
- This is
ogl-edocfcode-golf
Test cases
"cbad" -> "abcd"
"ACBD" -> "ABCD"
"Cb-Ad" -> "Ab-Cd"
"caeBDF" -> "aBcDeF"
"aEcbDF" -> "abcDEF"
"ogl-edocf" -> "code-golf"
"W o,ollelrHd!" -> "Hello, World!"
"ti HIs SSta ET!" -> "tHis IS a tEST!"