Skip to content

Instantly share code, notes, and snippets.

@IPRIT
Last active July 29, 2018 12:34
Show Gist options
  • Select an option

  • Save IPRIT/58cbb2f0c4e96e330dd36381fcba6c63 to your computer and use it in GitHub Desktop.

Select an option

Save IPRIT/58cbb2f0c4e96e330dd36381fcba6c63 to your computer and use it in GitHub Desktop.
export function pluralize (number, word, postfixes) {
const mod10 = number % 10,
mod100 = number % 100;
let postfix = '';
if (mod100 >= 5 && mod100 < 21
|| mod10 >= 5 && mod10 <= 9
|| !mod10) {
postfix = postfixes[2];
} else if (mod10 === 1) {
postfix = postfixes[0];
} else {
postfix = postfixes[1];
}
return `${word}${postfix}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment