Files
frontend/packages/pluralize/index.js

15 lines
374 B
JavaScript

export const pluralize = (count, words) => {
const normalizedCount = Math.abs(count) % 100;
const count10 = normalizedCount % 10;
if (normalizedCount > 10 && normalizedCount < 20) {
return words[2];
}
if (count10 > 1 && count10 < 5) {
return words[1];
}
if (count10 === 1) {
return words[0];
}
return words[2];
};