Skip to content

Commit 2abaae2

Browse files
author
Ogbemi mene
committed
count function
1 parent 0f14126 commit 2abaae2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
2+
let count = 0;
3+
for (let i = 0; i < stringOfCharacters.length; i++) {
4+
if (stringOfCharacters[i] === findCharacter) {
5+
count++;
6+
}
7+
}
8+
return count;
39
}
410

511
module.exports = countChar;
12+
13+
// for mordern approach, we can use the following code
14+
// function countChar(stringOfCharacters, findCharacter) {
15+
// return stringOfCharacters.split(findCharacter).length - 1;
16+
// }
17+
// module.exports = countChar;

0 commit comments

Comments
 (0)