Created
November 23, 2015 13:21
-
-
Save tesmen/b7d66166ef2b95ddab7f to your computer and use it in GitHub Desktop.
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
function declension(amount, words) { | |
var digit = (Number(amount) > 20) ? Number(amount) % 10 : Number(amount); | |
if (digit >= 5 || digit == 0) { | |
return words[2] | |
} | |
if (digit >= 2) { | |
return words[1] | |
} | |
return words[0]; | |
} | |
function plural(amount, words) { | |
return amount + ' ' + declension(amount, words); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment