Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Sprint-3/2-practice-tdd/count.js

@hackertainment hackertainment Aug 7, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semicolon missing in line 8 and line 11.

fun fact: In the original design of JavaScript, there was no semicolon, but it has been added later on - so that nowadays JS programmers generally follow the practice of adding semicolon.

Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
// function countChar(stringOfCharacters, findCharacter) {
// return 5
// }
function countChar(stringOfCharacters, findCharacter) {
return 5
let countChar = 0;
for (let stringNum = 0; stringNum < stringOfCharacters.length; stringNum++) {
if (findCharacter === stringOfCharacters[stringNum]){
countChar++
}
}
return countChar
}

module.exports = countChar;
21 changes: 21 additions & 0 deletions Sprint-3/2-practice-tdd/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@ test("should count multiple occurrences of a character", () => {
expect(count).toEqual(5);
});

test("should count multiple occurrences of a character", () => {
const str = "aaa aa";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(5);
});

test("should count multiple occurrences of a character with random characters", () => {
const str = "ajhyabhaakaka";
const char = "a";
const count = countChar(str, char);
expect(count).toEqual(6);
})

Comment on lines +20 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two cases looks quite similar, they both have random characters in the middle of str, and they both start with char, and they both end with char.

// Scenario: No Occurrences
// Given the input string `str`,
// And a character `char` that does not exist within `str`.
// When the function is called with these inputs,
// Then it should return 0, indicating that no occurrences of `char` were found.
test("should return 0 with no occurrence of the character", () => {
const str ="abcd";
const char = "e";
const count = countChar(str, char);
expect(count).toEqual(0);
});
Comment on lines 34 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be one more boundary case making char has no occurrence in str. Can you think of that special case?


11 changes: 10 additions & 1 deletion Sprint-3/2-practice-tdd/get-ordinal-number.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the question requires to also handle 2nd and 3rd etc. Since the question itself may not be quite clear about that, you may clarify in slack channel. Thanks.

Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// function getOrdinalNumber(num) {
// return "1st";
// }

function getOrdinalNumber(num) {
return "1st";
let text = num.toString();
if (text === "11") {
return (text + "th");
}
return (text + "st");
}

// getOrdinalNumber(1)).toEqual("1st")
module.exports = getOrdinalNumber;
5 changes: 5 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the question requires to also handle 2nd and 3rd etc, then there will be more test cases.

Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ test("should append 'st' for numbers ending with 1, except those ending with 11"
expect(getOrdinalNumber(21)).toEqual("21st");
expect(getOrdinalNumber(131)).toEqual("131st");
});

test("should append 'th' for number 11", () => {
expect(getOrdinalNumber(11)).toEqual("11th");

});
Loading