Last active
August 15, 2023 19:45
-
-
Save snowiesuet/7f1716633b89cbde2b20dd76a05a5ca4 to your computer and use it in GitHub Desktop.
cassidoo interview question #313
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
/* 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