Skip to content

Instantly share code, notes, and snippets.

@technobulka technobulka/num_end.js
Last active Oct 13, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.