Skip to content

Commit 02f9da3

Browse files
committed
Work on sprint 3 1-get-angle-type
put in code using "if" function.
1 parent b31a586 commit 02f9da3

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
// function countChar(stringOfCharacters, findCharacter) {
2+
// return 5
3+
// }
14
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
5+
let countChar = 0;
6+
for (let stringNum = 0; stringNum < stringOfCharacters.length; stringNum++) {
7+
if (findCharacter === stringOfCharacters[stringNum]){
8+
countChar++
9+
}
10+
}
11+
return countChar
312
}
4-
513
module.exports = countChar;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,29 @@ test("should count multiple occurrences of a character", () => {
1717
expect(count).toEqual(5);
1818
});
1919

20+
test("should count multiple occurrences of a character", () => {
21+
const str = "aaa aa";
22+
const char = "a";
23+
const count = countChar(str, char);
24+
expect(count).toEqual(5);
25+
});
26+
27+
test("should count multiple occurrences of a character with random characters", () => {
28+
const str = "ajhyabhaakaka";
29+
const char = "a";
30+
const count = countChar(str, char);
31+
expect(count).toEqual(6);
32+
})
33+
2034
// Scenario: No Occurrences
2135
// Given the input string `str`,
2236
// And a character `char` that does not exist within `str`.
2337
// When the function is called with these inputs,
2438
// Then it should return 0, indicating that no occurrences of `char` were found.
39+
test("should return 0 with no occurrence of the character", () => {
40+
const str ="abcd";
41+
const char = "e";
42+
const count = countChar(str, char);
43+
expect(count).toEqual(0);
44+
});
45+

0 commit comments

Comments
 (0)