-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathremoveVowels.js
More file actions
31 lines (29 loc) · 838 Bytes
/
removeVowels.js
File metadata and controls
31 lines (29 loc) · 838 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 i = 0
let empty = ''
while (i < str.length) {
if ((str[i] !== 'a') && (str[i] !== 'e') && (str[i] !== 'i') && (str[i] !== 'o') && (str[i] !== 'u')) {
if ((str[i] !== 'A') && (str[i] !== 'E') && (str[i] !== 'I') && (str[i] !== 'O') && (str[i] !== 'U')) {
empty = empty + str[i]
}
}
i++
}
return empty
}
module.exports = removeVowels