Skip to content

Commit 1f4a688

Browse files
committed
changes to get-ordinal-numbers.js to use neater code to avoid evaluating the same expression multiple times
1 parent c7bf47b commit 1f4a688

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
function getOrdinalNumber(num) {
22
// return "1st";
3-
if (num % 100 >= 11 && num % 100 <= 13) {
4-
return num + "th";
5-
}
3+
``
4+
const lastTwoDigits = num % 100;
5+
if (lastTwoDigits >= 11 && lastTwoDigits<= 13)
6+
return num + "th";
7+
68
if (num % 10 === 1) {
79
return num + "st";
810
}

0 commit comments

Comments
 (0)