Skip to content

Instantly share code, notes, and snippets.

@digitalhitler
Created September 13, 2017 07:26
Show Gist options
  • Save digitalhitler/6a2618139168c0a35c52d4d1ab6fb6e3 to your computer and use it in GitHub Desktop.
Save digitalhitler/6a2618139168c0a35c52d4d1ab6fb6e3 to your computer and use it in GitHub Desktop.
Склонение слов в зависимости от количества на JS
function numericPlural(number, titles, prependNumber) {
prependNumber = prependNumber || false;
var cases = [2, 0, 1, 1, 1, 2];
return (prependNumbers === true : number + " " : "") + titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
/**
usage:
numericPlural(count, ['найдена', 'найдено', 'найдены'], true);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment