Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions Sprint-3/2-practice-tdd/get-ordinal-number.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
function getOrdinalNumber(num) {
let result;
if (num % 100 == 11 || num % 100 == 12 || num % 100 == 13){
let rem_100 = num % 100;
let rem_10 = num % 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could consider naming them lastDigit and lastTwoDigits (more human readable).

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. I have changed it.

if (rem_100 == 11 || rem_100 == 12 || rem_100 == 13){
result = num.toString() + "th";
}
else if (num % 10 == 1){
else if (rem_10 == 1){
result = num.toString() +"st";
}
else if (num % 10 == 2){
else if (rem_10 == 2){
result = num.toString() + "nd";
}
else if (num % 10 == 3){
else if (rem_10 == 3){
result = num.toString() + "rd";
}
else {
Expand Down
5 changes: 5 additions & 0 deletions Sprint-3/2-practice-tdd/get-ordinal-number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ test("should return '12th' for 12", () => {
test("should return '13th' for 13", () => {
expect(getOrdinalNumber(13)).toEqual("13th");
});
test("append 'nd' to numbers ending in 2, except those ending in 12", () => {
expect( getOrdinalNumber(2) ).toEqual("2nd");
expect( getOrdinalNumber(22) ).toEqual("22nd");
expect( getOrdinalNumber(132) ).toEqual("132nd");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just an example. Why not update the whole test script accordingly to make the test more comprehensive?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. I have added other tests.

8 changes: 4 additions & 4 deletions Sprint-3/2-practice-tdd/repeat.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function repeat(str, count) {

if (count < 0){
return null
throw new Error("Count must be positive number!");
}
else if (count == 0){
return ""
return "";
}
let result = "";
for ( let i=0; i<count; i++){
result +=str
result +=str;
}
return result
return result;
}

module.exports = repeat;
5 changes: 1 addition & 4 deletions Sprint-3/2-practice-tdd/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,5 @@ test("handle Count of 0", () => {
// When the repeat function is called with these inputs,
// Then it should throw an error or return an appropriate error message, as negative counts are not valid.
test("Negative Count", () => {
const str = "hello";
const count = -1;
const repeatedStr = repeat(str, count);
expect(repeatedStr).toEqual(null);
expect(() => repeat("hello", -1)).toThrow("Count must be positive number!");
});
Loading