-
Notifications
You must be signed in to change notification settings - Fork 0
/
disemvowelTrolls.js
44 lines (36 loc) · 1.1 KB
/
disemvowelTrolls.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
34
35
36
37
38
39
40
41
42
43
44
/* Trolls are attacking your comment section!
A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat.
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) {
return str
.split("")
.filter((element, index, arr) => {
return (
element !== "a" &&
element !== "e" &&
element !== "i" &&
element !== "o" &&
element !== "u" &&
element !== "A" &&
element !== "E" &&
element !== "I" &&
element !== "U" &&
element !== "O"
);
})
.join("");
}
console.log(disemvowel("This website is for losers LOL!"));
// favorite solution
function disemvowel(str) {
const vowels = ["a", "e", "i", "o", "u"];
return str
.split("")
.filter(function (el) {
return vowels.indexOf(el.toLowerCase()) == -1;
})
.join("");
}