-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw8Task2.js
More file actions
46 lines (38 loc) · 1010 Bytes
/
Copy pathhw8Task2.js
File metadata and controls
46 lines (38 loc) · 1010 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
38
39
40
41
42
43
44
45
46
const words = [
'umbrella',
'apple',
'ocean',
'independent',
'education',
'elephant',
'island',
'universe',
'environment',
'queue',
'tst'
]
const vowels = ['a', 'e', 'i', 'o', 'u'];
// newArray = []
// newArray2 = []
// function countVowels(word) {
// return word.split('').filter(char => vowels.includes(char.toLowerCase())).length;
// }
function countVowels(word) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
return word.split('').filter(char => vowels.includes(char.toLowerCase())).length;
}
function sortArray(array) {
return [...array].sort((a, b) => countVowels(a) - countVowels(b))
}
// function sortArray(array) {
// for (const word of array) {
// if (vowels.some(vowel => word.includes(vowel))) {
// newArray.push(word);
// }
// }
// newArray2 = newArray.sort((a, b) => {
// return countVowels(a) - countVowels(b)
// })
// return newArray2
// }
console.log(sortArray(words))