Skip to content

Commit 261b5b4

Browse files
committed
Remove redundant check
1 parent f1f96b4 commit 261b5b4

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
function getOrdinalNumber(num) {
2-
// handle special cases
3-
42
if (typeof num !== "number" || Number.isNaN(num)) {
53
throw new Error(`Invalid type for ${num}, expected Number`);
64
}
75

86
const snum = String(num); // num as a string
9-
const thList = ["0", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]; // list of numbers that should end up with th as a suffix
7+
const thList = ["11", "12", "13"]; // list of numbers that should end up with th as a suffix
108

119
const lastCharIndex = snum.length - 1;
1210
const lastOne = snum[lastCharIndex];
1311
const lastTwo = snum.slice(lastCharIndex - 1);
1412

15-
if (thList.includes(lastTwo) || thList.includes(lastOne)) {
13+
if (thList.includes(lastTwo)) {
1614
return snum + "th";
1715
}
1816

@@ -24,7 +22,7 @@ function getOrdinalNumber(num) {
2422
case "3":
2523
return snum + "rd";
2624
default:
27-
break;
25+
return snum + "th";
2826
}
2927
}
3028

0 commit comments

Comments
 (0)