We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f14126 commit 2abaae2Copy full SHA for 2abaae2
1 file changed
Sprint-3/2-practice-tdd/count.js
@@ -1,5 +1,17 @@
1
function countChar(stringOfCharacters, findCharacter) {
2
- return 5
+ let count = 0;
3
+ for (let i = 0; i < stringOfCharacters.length; i++) {
4
+ if (stringOfCharacters[i] === findCharacter) {
5
+ count++;
6
+ }
7
8
+ return count;
9
}
10
11
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