Skip to content

Commit ba243f3

Browse files
get-ordinal-number : write implement ordinal logic for numbers ending in 1, 2, and 3, but excluding 11, 12, and 13 respectively
1 parent 0987e51 commit ba243f3

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎practice-tdd/get-ordinal-number.js‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
export function getOrdinalNumber(num) {
2-
return "1st";
2+
//Given a number `num`, the function should return a string representing the ordinal form of that number.
3+
//When the number ends with 1, except those ending with 11,
4+
//Then the function should return a string by appending "st" to the number.
5+
if (num % 10 === 1 && num % 100 !== 11) return `${num}st`;
6+
7+
//When the number ends with 2, except those ending with 12,
8+
//Then the function should return a string by appending "nd" to the number.
9+
if (num % 10 === 2 && num % 100 !== 12) return `${num}nd`;
10+
11+
//When the number ends with 3, except those ending with 13,
12+
//Then the function should return a string by appending "rd" to the number.
13+
if (num % 10 === 3 && num % 100 !== 13) return `${num}rd`;
14+
15+
return `${num}th`;
316
}

0 commit comments

Comments
 (0)