Created
October 22, 2016 17:39
-
-
Save paulvales/113b08bdf3d4fc3beb2a5e0045d9729d 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 agetostr(age) { | |
var txt; | |
count = age % 100; | |
if (count >= 5 && count <= 20) { | |
txt = 'лет'; | |
} else { | |
count = count % 10; | |
if (count == 1) { | |
txt = 'год'; | |
} else if (count >= 2 && count <= 4) { | |
txt = 'года'; | |
} else { | |
txt = 'лет'; | |
} | |
} | |
return age+" "+txt; | |
} |
function plural(number, titles = ['год', 'года', 'лет']) {
cases = [2, 0, 1, 1, 1, 2];
return titles[ (number%100>4 && number%100<20)? 2 : cases[(number%10<5)?number%10:5] ];
}
from
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function agetostr(age) {
let txt, count = age % 100;
count >= 5 && count <= 20 ? txt = 'лет' : count = count % 10, count == 1 ? txt = 'год' : (count >= 2 && count <= 4) ? txt = 'года' : txt = 'лет';
return
${age} ${txt}
;}