Skip to content

Commit 62ef41d

Browse files
committed
completed the countChar function with a short clear description and the goal of this function is to count how many times a specific character appears in a given string
1 parent 5dd3b88 commit 62ef41d

File tree

1 file changed

+13
-2
lines changed
  • Sprint-3/3-mandatory-practice/implement

1 file changed

+13
-2
lines changed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0; // start a count with 0
3+
for (let char of stringOfCharacters) {
4+
// repeat for each character in the string
5+
if (char === findCharacter) {
6+
// check if the character matches the one we are looking for.
7+
count++; // if it does increase the count by 1.
8+
}
9+
}
10+
11+
return count;
312
}
13+
console.log(countChar("ahmad", "a")); // example usage should return 2.
14+
console.log(countChar("hello", "h")); // example usage should return 1;
415

5-
module.exports = countChar;
16+
module.exports = countChar;

0 commit comments

Comments
 (0)