Skip to content

Instantly share code, notes, and snippets.

@paulvales
Created October 22, 2016 17:39
Show Gist options
  • Save paulvales/113b08bdf3d4fc3beb2a5e0045d9729d to your computer and use it in GitHub Desktop.
Save paulvales/113b08bdf3d4fc3beb2a5e0045d9729d to your computer and use it in GitHub Desktop.
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;
}
@aleks-boyar
Copy link

Ty

@romahawk-ru
Copy link

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};
}

@symphograph
Copy link

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