While working on some coding exercises on codewars, I came across a simple one that requires creating a function called shortcut to eliminate all the lowercase vowels in a given string. Here are some examples:
shortcut("codewars") // --> cdwrs
shortcut("goodbye") // --> gdby
As a newbie, I tried to come up with a solution, but unfortunately, it doesn't seem to work and I'm not sure why.
function shortcut(string){
var stage1 = string.split('');
for (i = string.length-1; i >= 0; i--) {
if (stage1[i] === "a"||
stage1[i] === "e"||
stage1[i] === "i"||
stage1[i] === "o"||
stage1[i] === "u") {
stage1.splice(i,1)
;}
};
string = stage1.join('');
return shortcut;
}
I have a feeling that the issue might be related to how I'm handling arrays and strings. If you have any suggestions or alternative methods to achieve the same result, please let me know.