Skip to content

Commit e638e78

Browse files
committed
refactoring and updating get-ordinal-nuber.js file
1 parent 1b12778 commit e638e78

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
function getOrdinalNumber(num) {
2-
let last2Digit = num % 100;
3-
let las1Digit = num % 10;
2+
const last2Digit = num % 100;
3+
const last1Digit = num % 10;
4+
45
if (last2Digit >= 11 && last2Digit <= 13) {
56
return num + "th";
67
}
7-
if (las1Digit === 1) {
8-
return num + "st";
9-
} else if (las1Digit === 2) {
10-
return num + "nd";
11-
} else if (las1Digit === 3) {
12-
return num + "rd";
13-
} else {
14-
return num + "th";
8+
9+
switch (last1Digit) {
10+
case 1:
11+
return num + "st";
12+
case 2:
13+
return num + "nd";
14+
case 3:
15+
return num + "rd";
16+
default:
17+
return num + "th";
1518
}
1619
}
1720

0 commit comments

Comments
 (0)