Skip to content

Commit ec9e58e

Browse files
committedAug 30, 2024
Fix pluralization edge case for teens
1 parent 092cadc commit ec9e58e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎util/strings.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function pluralize(num: number) {
2-
if (num % 10 === 1) return `${num}st`;
3-
if (num % 10 === 2) return `${num}nd`;
4-
if (num % 10 === 3) return `${num}rd`;
2+
if (num % 10 === 1 && num !== 11) return `${num}st`; // 21st, but not 11th
3+
if (num % 10 === 2 && num !== 12) return `${num}nd`; // 32nd, but not 12th
4+
if (num % 10 === 3 && num !== 13) return `${num}rd`; // 63rd, but not 13th
55
return `${num}th`
66
}

0 commit comments

Comments
 (0)
Please sign in to comment.