-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveVowels.js
46 lines (32 loc) · 972 Bytes
/
removeVowels.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
// 1. Write a function that takes in a string and returns the string with all vowels removed.
//1 solution N1
function removeVowels(input) {
var index = 0;
var output = ''
while ( index < input.length) {
var char = input[index];
if(char !== 'a' && char !== 'e' && char !== 'i' && char !== 'o' && char !== 'u' &&
char !== 'A' && char !== 'E' && char !== 'I' && char !== 'O' && char !== 'U') {
output += char;
}
index++;
}
return output;
}
console.log(removeVowels('JavaScriptIscool'))
//output -> JvScrptscl
// solution N2
function removeVowels2(input){
var index = 0;
var output = ''
while ( index < input.length) {
var char = input[index];
if('AEIOUaeiou'.indexOf(char) === -1) {
output += char;
}
index++;
}
return output;
}
console.log(removeVowels2('JavaScriptIscool'))
//output -> JvScrptscl