Skip to content

Commit 4189d74

Browse files
committed
implement count of characters function in 2-practice-tdd
1 parent b31a586 commit 4189d74

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1-
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
1+
function countChar(str, char) {
2+
const arrayOfChars = Array.from(str);
3+
let count = 0;
4+
for (letter of arrayOfChars) {
5+
if (char === letter) {
6+
count++;
7+
}
8+
}
9+
return count;
310
}
411

512
module.exports = countChar;
13+
countChar("absge", "a");
14+
15+
//check if the code looks correct
16+
console.log(countChar("shdhhshd", "h"));

0 commit comments

Comments
 (0)