Skip to content

Instantly share code, notes, and snippets.

@snowiesuet
Last active August 15, 2023 19:45
Show Gist options
  • Save snowiesuet/7f1716633b89cbde2b20dd76a05a5ca4 to your computer and use it in GitHub Desktop.
Save snowiesuet/7f1716633b89cbde2b20dd76a05a5ca4 to your computer and use it in GitHub Desktop.
cassidoo interview question #313
/* 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.
Example:
> faultyKeeb('string')
> 'rtsng'
> faultyKeeb('hello world!')
> 'w hllrld!'
*/
let vowels = ['a', 'e', 'i','o','u'];
function faultyKeeb(string){
let nonVowels = [];
for (let i = 0; i < string.length; i++) {
// if not a vowel, add the string to nonvowel
if(!vowels.includes(string[i])){
nonVowels.push(string[i]);
}
else{
nonVowels.reverse();
}
}
return nonVowels.join('');
}
faultyKeeb("hello world");
faultyKeeb('string');
faultyKeeb("rendezvous with cassidoo");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment