-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindthevowels.js
More file actions
37 lines (32 loc) · 898 Bytes
/
Copy pathFindthevowels.js
File metadata and controls
37 lines (32 loc) · 898 Bytes
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
// We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).
// So given a string "super", we should return a list of [2, 4].
// Some examples:
// Mmmm => []
// Super => [2,4]
// Apple => [1,5]
// YoMama -> [1,2,4,6]
function vowelIndices(word){
//your code here
let vowel = ['a', 'e', 'i', 'o', 'u', 'y'];
let arrOfIndeces = []
//loop thru string of word
for(let i = 0; i < word.length; i++){
//if the vowel has the letter lowercase
if(vowel.includes(word[i].toLowerCase())){
//then push into the new arr
arrOfIndeces.push(i + 1)
}
}
//return new arr
return arrOfIndeces
}
//different approach
function vowelIndices(word) {
const arr = [];
for(let i = 0; i < word.length; i++) {
if(/[aeioyu]/i.test(word[i])) {
arr.push(i+1);
}
}
return arr;
}