Skip to content

Commit 37dd0e7

Browse files
author
hasibulislam999
committed
Vowels of All Substrings problem solved
1 parent 331cfa4 commit 37dd0e7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Title: Vowels of All Substrings
3+
* Description: Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.
4+
* Author: Hasibul Islam
5+
* Date: 03/05/2023
6+
*/
7+
8+
/**
9+
* @param {string} word
10+
* @return {number}
11+
*/
12+
var countVowels = function (word) {
13+
const vowels = new Set(["a", "e", "i", "o", "u"]);
14+
let total = 0;
15+
let count = 0;
16+
for (let i = 0; i < word.length; i++) {
17+
if (vowels.has(word[i])) {
18+
count += i + 1;
19+
}
20+
total += count;
21+
}
22+
return total;
23+
};

0 commit comments

Comments
 (0)