Created
August 14, 2023 11:13
-
-
Save Pro542/8911ee62af0e6d9538e1fd8db7a2857d to your computer and use it in GitHub Desktop.
You have a faulty keyboard. Whenever you type a vowel on it (a,e,i,o,u,y), it reverses the string that you have written, instead of typing the character. Typing other characters works as expected. Given a string, return what will be on the screen after typing with your faulty keyboard.
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 faultyKeeb(str) { | |
for (let i = 0; i < str.length; ++i) { | |
if (['a', 'e', 'i', 'o', 'u'].includes(str[i])) { | |
str = Array.from(str.slice(0, i)).reverse().join('') + str.slice(i+1, str.length); | |
} | |
} | |
return str; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment