Skip to content

Instantly share code, notes, and snippets.

@technobulka
Last active October 13, 2015 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technobulka/4274964 to your computer and use it in GitHub Desktop.
Save technobulka/4274964 to your computer and use it in GitHub Desktop.
Numeral Ends
function numEnd(n,t){return t[n%100>4&&n%100<20?2:'201112'[n%10<5?n%10:5]]}
// test
var a = [1, 2, 5, 10, 20, 21, 22],
i = 0;
for (i in a) {
console.log(a[i] + ' котик' + numEnd(a[i], ['', 'а', 'ов']));
}
for (i in a) {
console.log(a[i] + ' ' + numEnd(a[i], ['котик', 'котика', 'котиков']));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment