Skip to content

Commit 6d8d7bb

Browse files
committed
Implement countChar function to count occurrences of a character in a string
1 parent 633a7af commit 6d8d7bb

File tree

1 file changed

+7
-1
lines changed
  • Sprint-3/3-mandatory-practice/implement

1 file changed

+7
-1
lines changed
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0;
3+
for (let char of stringOfCharacters) {
4+
if (char === findCharacter) {
5+
count++;
6+
}
7+
}
8+
return count;
39
}
410

511
module.exports = countChar;

0 commit comments

Comments
 (0)