-
Notifications
You must be signed in to change notification settings - Fork 0
/
vowel-remover.js
48 lines (42 loc) · 1.25 KB
/
vowel-remover.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
45
46
47
48
/* Create a function called shortcut to remove the lowercase vowels (a, e, i, o, u ) in a given string. */
// solution
// create arrays for vowels
// convert string to array
// compare each member array of char with array of vowels and remove it if it is equal to any one of them
// convert the new filtered arr to string
// return the string
// first way
function shortcut(string) {
let vowels = ["a", "e", "i", "o", "u"];
let arrOfStrChar = Array.from(string);
console.log(arrOfStrChar);
let newStr = "";
for (let i = 0; i < arrOfStrChar.length; i++) {
if (vowels.includes(arrOfStrChar[i])) {
continue;
} else {
newStr += arrOfStrChar[i];
}
}
return newStr;
}
// second way
// function shortcut(string) {
// let vowels = ["a", "e", "i", "o", "u"];
// let arrOfStrChar = Array.from(string);
// let newStr = "";
// for (let i = 0; i < arrOfStrChar.length; i++) {
// let isVowel = false;
// for (let g = 0; g < vowels.length; g++) {
// if (arrOfStrChar[i] === vowels[g]) {
// isVowel = true;
// break;
// }
// }
// if (!isVowel) {
// newStr += arrOfStrChar[i];
// }
// }
// return newStr;
// }
console.log(shortcut("ahmedsaleh"));