-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathremoveVowels.js
More file actions
39 lines (37 loc) · 954 Bytes
/
removeVowels.js
File metadata and controls
39 lines (37 loc) · 954 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
32
33
34
35
36
37
38
39
/**
* 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 str2 = str.toLowerCase()
let word = ''
for (let i = 0; i < str2.length; i++) {
if ((str2[i] === 'a') || (str2[i] === 'e') || (str2[i] === 'o') || (str2[i] === 'i') || (str2[i] === 'u')) {
word = word + ""
}
else {
word = word + str[i]
}
}
return word
}
// let newStr = ""
// let vowels = ['a','A','e','E','i','I','o','O','u','U']
// for (let i = 0; i < str.length; i++){
// if (!vowels.includes(str[i])){
//newStr += str[i]
// }
// }
// return newStr
module.exports = removeVowels