There was an error while loading. Please reload this page.
1 parent 1526faf commit 47d8723Copy full SHA for 47d8723
1 file changed
Sprint-3/2-practice-tdd/get-ordinal-number.js
@@ -1,5 +1,11 @@
1
function getOrdinalNumber(num) {
2
- return "1st";
+ const lastTwo = num % 100;
3
+ const lastOne = num % 10;
4
+ if (lastTwo >= 11 && lastTwo <= 13) return `${num}th`;
5
+ if (lastOne === 1) return `${num}st`;
6
+ if (lastOne === 2) return `${num}nd`;
7
+ if (lastOne === 3) return `${num}rd`;
8
+ return `${num}th`;
9
}
10
11
module.exports = getOrdinalNumber;
0 commit comments