Skip to content

Commit e947150

Browse files
removed redundant checks and added check for negative values
1 parent 11c8346 commit e947150

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function getOrdinalNumber(num) {
22
// Check if input is a number
3-
if (typeof num !== "number" || isNaN(num)) || !Number.isInteger(num) || !Number.isFinite(num)) {
3+
if (!Number.isInteger(num) || !Number.isFinite(num) || num <= 0) {
44
throw new Error("Input must be a valid number");
55
}
66

77
const lastnum = num % 10; // checks what last number is
8-
const last2num = % 100; // checks what last two numbers are, needed to check for 11
8+
const last2num = num % 100; // checks what last two numbers are, needed to check for 11
99

1010
if (last2num === 11 || last2num === 12 || last2num === 13) {
1111
return num + "th";

0 commit comments

Comments
 (0)