Skip to content

Commit b02a77f

Browse files
committed
Editing count code
1 parent ef42f92 commit b02a77f

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
3-
}
2+
return stringOfCharacters.split(findCharacter).length - 1;
3+
}
44

55
module.exports = countChar;
6+
console.log(countChar('hello', 'l'));
7+
console.log(countChar('hello', 'z'));
8+
console.log(countChar('alaaa', 'a'));
9+

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
const countChar = require("./count");
33
// Given a string str and a single character char to search for,
44
// When the countChar function is called with these inputs,
5-
// Then it should:
5+
// Then it should: correctly count the occurrences of char in str.
6+
67

78
// Scenario: Multiple Occurrences
89
// Given the input string str,
@@ -17,8 +18,16 @@ test("should count multiple occurrences of a character", () => {
1718
expect(count).toEqual(5);
1819
});
1920

21+
2022
// Scenario: No Occurrences
2123
// Given the input string str,
2224
// And a character char that does not exist within the case-sensitive str,
2325
// When the function is called with these inputs,
2426
// Then it should return 0, indicating that no occurrences of the char were found in the case-sensitive str.
27+
28+
test("should return 0 for no occurrences", () => {
29+
const str = "hello";
30+
const char = "z";
31+
const count = countChar(str, char);
32+
expect(count).toEqual(0);
33+
});
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
if (num === 1) {
3+
return "1st";
4+
}
5+
if (num === 2) {
6+
return "2nd";
7+
}
8+
if (num === 3) {
9+
return "3rd";
10+
}
11+
return num + "th";
312
}
413

514
module.exports = getOrdinalNumber;
15+
console.log(getOrdinalNumber(1));
16+
console.log(getOrdinalNumber(2));
17+
console.log(getOrdinalNumber(3));
18+
console.log(getOrdinalNumber(4));
19+
console.log(getOrdinalNumber(11));
20+
console.log(getOrdinalNumber(22));

0 commit comments

Comments
 (0)