Skip to content

Instantly share code, notes, and snippets.

@Pro542
Created August 14, 2023 11:13
Show Gist options
  • Save Pro542/8911ee62af0e6d9538e1fd8db7a2857d to your computer and use it in GitHub Desktop.
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.
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