Skip to content

Commit 26e3e7d

Browse files
committed
Adjustments and changes made to the repeatStr function and its corresponding test cases to ensure that it handles various scenarios correctly, including edge cases such as a count of 0 and negative counts. The implementation now includes error handling for invalid input, and the test cases have been expanded to cover these new scenarios.
1 parent 3372770 commit 26e3e7d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,20 @@ function countChar(stringOfCharacters, findCharacter) {
33
}
44

55
module.exports = countChar;
6+
//
7+
8+
//Below is the implementation of the countChar function that counts the number of times a character occurs in a string.
9+
// The function takes two parameters: `stringOfCharacters`, which is the string to search through, and `findCharacter`, which is the character to count.
10+
// The function initializes a counter to 0 and iterates through each character in the string. If the current character matches `findCharacter`, the counter is incremented. Finally, the function returns the total count.
11+
12+
function countChar(stringOfCharacters, findCharacter) {
13+
let count = 0;
14+
for (let i = 0; i < stringOfCharacters.length; i++) {
15+
if (stringOfCharacters[i] === findCharacter) {
16+
count++;
17+
}
18+
}
19+
return count;
20+
}
21+
22+
module.exports = countChar;

0 commit comments

Comments
 (0)