Created
October 25, 2010 16:02
-
-
Save ChillyBwoy/645200 to your computer and use it in GitHub Desktop.
plural ru
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
var pluralRu = function pluralRu(value) { | |
if (arguments.length != 4) throw "Wrong number of arguments" | |
var number = Math.abs(value), | |
one = arguments[1] || '', two = arguments[2] || '', five = arguments[3] || ''; | |
number %= 100; | |
if (number >= 5 && number <= 20) return five; | |
number %= 10; | |
if (number == 1) return one; | |
if (number >= 2 && number <= 4) return two; | |
return five; | |
} | |
/* | |
usage: | |
pluralRu(1, 'яблоко', 'яблока', 'яблок') | |
pluralRu(4, 'яблоко', 'яблока', 'яблок') | |
pluralRu(10, 'яблоко', 'яблока', 'яблок') | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment