-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7kyuDisemvowelTrolls.js
33 lines (28 loc) · 1017 Bytes
/
7kyuDisemvowelTrolls.js
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
//Your task is to write a function that takes a string and return a new string with all vowels removed. For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!". Note: for this kata y isn't considered a vowel.
function disemvowel(str) {
const vowels = ['a','e','i','o','u','A','E','I','O','U'];
const chars = str.split('');
const filteredChars = chars.filter(function(char) {
return !vowels.includes(char);
});
const result = filteredChars.join('');
return result;
};
//or
function disemvowel(str) {
const splitStr = str.split('')
const vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];
const filteredArr = splitStr.filter(e => !vowels.includes(e))
return filteredArr.join('');
}
//solution 2
function disemvowel(str) {
const vowels = new Set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']);
let result = '';
for (let char of str) {
if (!vowels.has(char)) {
result += char;
}
}
return result;
}