0
0
GGGiovanny Gongora
Takes a number and returns it as a string with the correct ordinal indicator suffix.
const toOrdinalSuffix = (num: string) => {
const int: number = parseInt(num),
digits: number[] = [int % 10, int % 100],
ordinals: string[] = ['st', 'nd', 'rd', 'th'],
oPattern: number[] = [1, 2, 3, 4],
tPattern: number[] = [11, 12, 13, 14, 15, 16, 17, 18, 19];
return oPattern.includes(digits[0]) && !tPattern.includes(digits[1])
? int + ordinals[digits[0] - 1]
: int + ordinals[3];
};