-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathremoveVowels.js
More file actions
31 lines (28 loc) · 826 Bytes
/
removeVowels.js
File metadata and controls
31 lines (28 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Removes all vowels from an input string.
* For this problem, treat y as a consonant, not a vowel.
* Vowels are "a", "e", "i", "o", and "u" (upper and lowercase)
*
* @param {string} str - The input string
* @returns {string} - Returns a new string without any vowels.
*
* ex: removeVowels("HELLO")
* returns: "HLL"
*
* ex: removeVowels("Sunny")
* returns: "Snny"
*
*/
function removeVowels(str) {
let trash = ''
let filtered = ''
for(let i = 0;i<str.length;i++){
if(str[i] === 'a' || str[i] === 'e' ||str[i]=== 'i'||str[i] ==='o'||str[i] === 'u'||str[i] === 'A' || str[i] === 'E' ||str[i]=== 'I'||str[i] ==='O'||str[i] === 'U'){
trash = trash + str[i]
} else{
filtered = filtered + str[i]
}
}
return filtered
}
module.exports = removeVowels