Skip to content

Commit d269acc

Browse files
authored
Editing the code and jest code
1 parent 5e24460 commit d269acc

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return stringOfCharacters.split(findCharacter).length - 1;
2+
if (
3+
typeof stringOfCharacters !== "string" ||
4+
typeof findCharacter !== "string" ||
5+
findCharacter.length !== 1
6+
) {
7+
return 0;
38
}
49

5-
module.exports = countChar;
10+
if (stringOfCharacters.length === 0) {
11+
return 0;
12+
}
613

14+
return stringOfCharacters.split(findCharacter).length - 1;
15+
}
716

17+
module.exports = countChar;

0 commit comments

Comments
 (0)