Skip to content

Commit 7b67103

Browse files
Make some minor chang for PR again
1 parent 1063a4d commit 7b67103

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
11
function getOrdinalNumber(num) {
2-
// This is for num argument validation that go inside the function.
3-
if(typeof num !== "number" || Number.isNaN(num) || !Number.isInteger(num)){
4-
throw new Error ("Invalid input: the value must be a number");
5-
}
6-
7-
// This allow float number to be round into it nearest integer.
8-
const mainReminder = num % 100;
9-
const secondReminder = num % 10;
10-
11-
if(mainReminder === 11 ||mainReminder === 12 || mainReminder === 13 ){
12-
return `${num}th`;
13-
}
14-
switch( true ){
15-
case secondReminder === 1 : return `${num}st`;
16-
case secondReminder=== 2 : return `${num}nd`;
17-
case secondReminder=== 3 : return `${num}rd`;
18-
default : return `${num}th`;
19-
}
2+
// This is for num argument validation that go inside the function.
3+
if ( !Number.isInteger(num)) {
4+
throw new Error("Invalid input: the value must be a number");
5+
}
6+
7+
// This allow float number to be round into it nearest integer.
8+
const mainReminder = num % 100;
9+
const secondReminder = num % 10;
10+
11+
if (mainReminder === 11 || mainReminder === 12 || mainReminder === 13) {
12+
return `${num}th`;
13+
}
14+
switch (true) {
15+
case secondReminder === 1:
16+
return `${num}st`;
17+
case secondReminder === 2:
18+
return `${num}nd`;
19+
case secondReminder === 3:
20+
return `${num}rd`;
21+
default:
22+
return `${num}th`;
23+
}
2024
}
2125

2226
module.exports = getOrdinalNumber;
2327

24-
25-
function testAssert (inputNumber,outputNUmber){
26-
console.assert(
27-
inputNumber === outputNUmber,
28-
`Test failed: expected ${outputNUmber}, but got ${inputNumber}`
29-
);
30-
};
28+
function testAssert(inputNumber, outputNUmber) {
29+
console.assert(
30+
inputNumber === outputNUmber,
31+
`Test failed: expected ${outputNUmber}, but got ${inputNumber}`
32+
);
33+
}
3134
//Basic test of first digit integer
3235
testAssert(getOrdinalNumber(1), "1st");
3336
testAssert(getOrdinalNumber(2), "2nd");
3437
testAssert(getOrdinalNumber(3), "3rd");
3538
testAssert(getOrdinalNumber(4), "4th");
36-
//Test for 11, 12 and 13
39+
//Test for 11, 12 and 13
3740
testAssert(getOrdinalNumber(11), "11th");
3841
testAssert(getOrdinalNumber(12), "12th");
3942
testAssert(getOrdinalNumber(13), "13th");
@@ -44,8 +47,5 @@ testAssert(getOrdinalNumber(43), "43rd");
4447
//Normal number and float number test.
4548
testAssert(getOrdinalNumber(101), "101st");
4649
testAssert(getOrdinalNumber(202), "202nd");
47-
testAssert(() =>getOrdinalNumber(1.2),"Invalid input" );
48-
testAssert(() =>getOrdinalNumber(10.51),"Invalid input");
49-
50-
51-
50+
testAssert(() => getOrdinalNumber(1.2), "Invalid input");
51+
testAssert(() => getOrdinalNumber(10.51), "Invalid input");

Sprint-3/2-practice-tdd/get-ordinal-number.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test("should append 'th' for special cases 11, 12, 13", () => {
5151
// Case 5: All other numbers that is not end in 1,2 or 3.
5252
// When the number does not end with 1, 2, or 3,
5353
// Then the function should append "th".
54-
test("should append 'th' for all other numbers", () => {
54+
test("should append 'th' for all number that don't end in 1,2 or 3", () => {
5555
expect(getOrdinalNumber(4)).toEqual("4th");
5656
expect(getOrdinalNumber(10)).toEqual("10th");
5757
expect(getOrdinalNumber(100)).toEqual("100th");
@@ -62,12 +62,12 @@ test("should append 'th' for all other numbers", () => {
6262
// When the input is a float,
6363
// Then the function should round it and return the correct ordinal.
6464
test("should return error for invalid input", () => {
65-
expect(() =>getOrdinalNumber(1.2)).toThrow("Invalid input");
66-
expect(() =>getOrdinalNumber(1.8)).toThrow("Invalid input");
67-
expect(() =>getOrdinalNumber(2.5)).toThrow("Invalid input");
68-
expect(() =>getOrdinalNumber(10.51)).toThrow("Invalid input");
69-
expect(() =>getOrdinalNumber(12.49)).toThrow("Invalid input");
70-
expect(() =>getOrdinalNumber(12.5)).toThrow("Invalid input");
65+
expect(() => getOrdinalNumber(1.2)).toThrow("Invalid input");
66+
expect(() => getOrdinalNumber(1.8)).toThrow("Invalid input");
67+
expect(() => getOrdinalNumber(2.5)).toThrow("Invalid input");
68+
expect(() => getOrdinalNumber(10.51)).toThrow("Invalid input");
69+
expect(() => getOrdinalNumber(12.49)).toThrow("Invalid input");
70+
expect(() => getOrdinalNumber(12.5)).toThrow("Invalid input");
7171
});
7272

7373
// Case 7: Invalid inputs should throw an error

0 commit comments

Comments
 (0)