Skip to content

Commit 3d45d8a

Browse files
authored
Restrict input to integers in get-ordinal-number.js
Added validation to ensure input is an integer.
1 parent 0ac1333 commit 3d45d8a

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ function getOrdinalNumber(num) {
33
if (typeof num !== "number" || Number.isNaN(num)) {
44
throw new TypeError("Input must be a number");
55
}
6+
// Strict: only allow integers
7+
if (!Number.isInteger(num)) {
8+
throw new TypeError("Input must be an integer");
9+
}
610

711
const abs = Math.abs(num);
812
const lastTwoDigits = abs % 100;

0 commit comments

Comments
 (0)