Skip to content

Commit 049a281

Browse files
authored
Implement character counting in countChar function
Fix countChar function to correctly count occurrences of a character in a string.
1 parent 3372770 commit 049a281

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Sprint-3/2-practice-tdd/count.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
function countChar(stringOfCharacters, findCharacter) {
22
return 5
3+
let count = 0;
4+
for (let i = 0; i < stringOfCharacters.length; i++) {
5+
if (stringOfCharacters[i] === findCharacter) {
6+
count++;
7+
}
8+
}
9+
return count;
310
}
411

512
module.exports = countChar;

0 commit comments

Comments
 (0)