0 points

Add English Ordinal Suffices


dashboard

Tue Dec 01 2020 04:24:49 GMT+0000 (UTC)

Posted by @eneki

function addEnglishOrdinalSuffixes(number) {
        const english_ordinal_rules = new Intl.PluralRules("en", {
            type: "ordinal"
        });
        const suffixes = {
            one: "st",
            two: "nd",
            few: "rd",
            other: "th"
        }
        const suffix = suffixes[english_ordinal_rules.select(number)];
        return (number + suffix);
    }
content_copy Copy