Skip to content

Commit 7561430

Browse files
committed
using .slice() instead of index to extract the last character
1 parent 28288c3 commit 7561430

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ function getOrdinalNumber(num) {
22
let lastDigit = num % 10;
33
let lastTwoDigits = num % 100;
44
if (lastDigit === 1 && lastTwoDigits !== 11) {
5-
// we also can use if (num[-1]==="1" && num.slice(-2)!=="11")
5+
// we also can use if (num.slice(-1)==="1" && num.slice(-2)!=="11")
66
return num + "st";
77
} else if (lastDigit === 2 && lastTwoDigits !== 12) {
8-
// we also can use if (num[-1]==="2" && num.slice(-2)!=="12")
8+
// we also can use if (num.slice(-1)==="2" && num.slice(-2)!=="12")
99
return num + "nd";
1010
} else if (lastDigit === 3 && lastTwoDigits !== 13) {
11-
// we also can use if (num[-1]==="3" && num.slice(-2)!=="13")
11+
// we also can use if (num.slice(-1)==="3" && num.slice(-2)!=="13")
1212
return num + "rd";
1313
} else {
1414
return num + "th";

0 commit comments

Comments
 (0)