Skip to content

Commit c4f51fb

Browse files
1 ques @ 13/4/23
1 parent 3d9cd82 commit c4f51fb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

vowelCount.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Ques Link: https://www.codewars.com/kata/54ff3102c1bad923760001f3/train/javascript
2+
3+
/*
4+
Return the number (count) of vowels in the given string.
5+
6+
We will consider a, e, i, o, u as vowels for this Kata (but not y).
7+
8+
The input string will only consist of lower case letters and/or spaces.
9+
*/
10+
11+
// Sol:
12+
13+
const getCount = (str) => {
14+
return str.split("").reduce((acc, curr) => {
15+
if (
16+
curr === "a" ||
17+
curr === "e" ||
18+
curr === "i" ||
19+
curr === "o" ||
20+
curr === "u"
21+
) {
22+
acc += 1;
23+
}
24+
return acc;
25+
}, 0);
26+
};
27+
28+
// Test Cases:
29+
30+
const { assert } = require("chai");
31+
32+
describe("Vowels Count Tests", function () {
33+
it("should return 5 for 'abracadabra'", function () {
34+
assert.strictEqual(getCount("abracadabra"), 5);
35+
});
36+
});

0 commit comments

Comments
 (0)