Last active
July 29, 2018 12:34
-
-
Save IPRIT/58cbb2f0c4e96e330dd36381fcba6c63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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