-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathremoveVowels.js
More file actions
47 lines (40 loc) · 1.13 KB
/
removeVowels.js
File metadata and controls
47 lines (40 loc) · 1.13 KB
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
40
41
42
43
44
45
46
47
/**
* 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"
*
*/
// will take in a string
// will return a new string without the vowels
// we do this by splitting the string into an array with str.split('')
// we then iterate through the newArr
//
function removeVowels(str) {
let vowel = "aeiou" + "aeiou".toUpperCase()
let newStr = str
let chars
for (let i = 0; i < vowel.length; i++) {
console.log(chars, newStr)
chars = newStr.split(vowel[i])
newStr = chars.join('')
}
return newStr
}
console.log(removeVowels("Hello kiddo"))
// let yourName = 'Ivan'
// yourName.split === String.prototype.split
// true
// yourName.prototype === String.prototype
// false
// String.prototype is the entire name of the object.
// It has a bunch of methods, but no properties
module.exports = removeVowels