Skip to content

Instantly share code, notes, and snippets.

@Inontran
Created August 27, 2021 12:57
Show Gist options
  • Select an option

  • Save Inontran/bf5e41ce1aacbaa42024982b9648aa94 to your computer and use it in GitHub Desktop.

Select an option

Save Inontran/bf5e41ce1aacbaa42024982b9648aa94 to your computer and use it in GitHub Desktop.
склонение слов в зависимости от числителя
//declineWord
function declineWord(number, titles){
const numberOfEnding = [2, 0, 1, 1, 1, 2];
const isLastEnding = number % 100 > 4 && number % 100 < 20;
const correctEnding = (number % 10 < 5) ? number % 10 : 5;
return titles[isLastEnding ? 2 : numberOfEnding[correctEnding]];
//use:
//declineWord(count, ['гость', 'гостя', 'гостей']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment