Skip to content

Commit 7991a9b

Browse files
author
Ogbemi mene
committed
getting ordinal num
1 parent 9733fa3 commit 7991a9b

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@ function getOrdinalNumber(num) {
33
}
44

55
module.exports = getOrdinalNumber;
6+
// this is a code i came up with to get the ordinal number of a given number.
7+
// I will now write tests to check if it works correctly.
8+
9+
function getOrdinalNumber(n) {
10+
const pr = new Intl.PluralRules("en-US", { type: "ordinal" });
11+
const suffixes = { one: "st", two: "nd", few: "rd", other: "th" };
12+
const rule = pr.select(n);
13+
return `${n}${suffixes[rule]}`;
14+
}

0 commit comments

Comments
 (0)