-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path48.js
More file actions
33 lines (24 loc) · 802 Bytes
/
Copy path48.js
File metadata and controls
33 lines (24 loc) · 802 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
function stringCode(sentence){
function isConsonant(char){
const consonants = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
return consonants.includes(char);
}
function countConsonantsAndVowels(word){
let consonants = 0;
let vowels = 0;
for(const char of word){
if(isConsonant(char)){
consonants++;
}
else if("aeiouAEIOU".includes(char)){
vowels++;
}
}
return consonants + " " +vowels;
}
const words = sentence.split(' ');
console.log(words);
const consonantCount = words.map(word => countConsonantsAndVowels(word));
return consonantCount;
}
console.log(stringCode("Happy Birthday To Me"))