Skip to content

Commit 860057a

Browse files
committed
commit
1 parent 3372770 commit 860057a

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
function countChar(stringOfCharacters, findCharacter) {
2-
return 5
3-
}
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}
49

510
module.exports = countChar;
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
// implement a function countChar that counts the number of times a character occurs in a string
21
const countChar = require("./count");
32
// Given a string `str` and a single character `char` to search for,
43
// When the countChar function is called with these inputs,
5-
// Then it should:
4+
// Then it should:
5+
test("should count occurrences of a character", () => {
6+
expect(countChar("tired", "d")).toEqual(1)
7+
})
68

7-
// Scenario: Multiple Occurrences
8-
// Given the input string `str`,
9-
// And a character `char` that occurs one or more times in `str` (e.g., 'a' in 'aaaaa'),
10-
// When the function is called with these inputs,
11-
// Then it should correctly count occurrences of `char`.
129

13-
test("should count multiple occurrences of a character", () => {
14-
const str = "aaaaa";
15-
const char = "a";
16-
const count = countChar(str, char);
17-
expect(count).toEqual(5);
18-
});
19-
20-
// Scenario: No Occurrences
10+
// Scenario: Multiple Occurrences
2111
// Given the input string `str`,
2212
// And a character `char` that does not exist within `str`.
2313
// When the function is called with these inputs,
2414
// Then it should return 0, indicating that no occurrences of `char` were found.
15+
test("should count no occurrences of a character", () => {
16+
expect(countChar("bananataste","w")).toEqual(0)
17+
})
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+
let lastDigit = num % 10;
3+
let lastTwoDigits = num % 100;
4+
if (lastTwoDigits >= 11 && lastTwoDigits <= 13) {
5+
return num + "th";
6+
}
7+
8+
switch (lastDigit) {
9+
case 1:
10+
return num + "st";
11+
case 2:
12+
return num + "nd";
13+
case 3:
14+
return num + "rd";
15+
default:
16+
return num + "th";
17+
}
318
}
419

520
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)