Last active
June 14, 2020 20:52
-
-
Save vladislav805/c627586d915da64aa2ad9e069492f14d to your computer and use it in GitHub Desktop.
Pluralize: 1 item, 2 items, 5 items / 1 элемент, 2 элемента, 5 элементов
This file contains 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 const pluralize = (number, cases) => { | |
number = Math.abs(number); | |
return cases[number % 100 > 4 && number % 100 < 20 ? 2 : [2, 0, 1, 1, 1, 2][number % 10 < 5 ? number % 10 : 5]]; | |
}; |
This file contains 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 const pluralize = (n: number, cases: [string, string, string]): string => { | |
n = Math.abs(n); | |
return cases[n % 100 > 4 && n % 100 < 20 ? 2 : [2, 0, 1, 1, 1, 2][n % 10 < 5 ? n % 10 : 5]]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment