Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ToTheHit/01ba5054b50d77551a69f9d09536d9fa to your computer and use it in GitHub Desktop.
Save ToTheHit/01ba5054b50d77551a69f9d09536d9fa to your computer and use it in GitHub Desktop.
const getCorrectWord = (count, words = []) => {
const cases = [2, 0, 1, 1, 1, 2];
return words[(count % 100 > 4 && count % 100 < 20) ? 2 : cases[(count % 10 < 5) ? count % 10 : 5]];
}
/*
EXAMPLE
const minutes = 33;
const message = `До приезда осталось ${minutes} ${getCorrectWord(minutes, ['минута', 'минуты', 'минут'])}`
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment