Skip to content

Commit 47d8723

Browse files
committed
Implement getOrdinalNumber with TDD
1 parent 1526faf commit 47d8723

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
function getOrdinalNumber(num) {
2-
return "1st";
2+
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`;
39
}
410

511
module.exports = getOrdinalNumber;

0 commit comments

Comments
 (0)