Skip to content

Commit 4b39af7

Browse files
committed
Added lines to check cases and return count of characters.
1 parent 8f3d6cf commit 4b39af7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
if (typeof stringOfCharacters!= "string") {
3+
throw new Error("Input should be a string");
4+
}
5+
if (typeof findCharacter !== "string" || findCharacter.length != 1){
6+
throw new Error ("Input must be a single character");
7+
}
8+
9+
let count = 0;
10+
for(let char of stringOfCharacters) {
11+
if (char === findCharacter) {
12+
count++;
13+
}
14+
}
15+
return count;
16+
317
}
418

519
module.exports = countChar;
20+
21+
console.log(countChar("amazon", "a"));
22+
23+
// Added lines to check cases and return count of characters.

0 commit comments

Comments
 (0)