ordanizlie

Javascript code posted
created at 20 Apr 09:54

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Number.prototype.ordinalize = function() {
    var abs = Math.abs(this);
    
    if (abs % 100 >= 11 && abs % 100 <= 13) {
        return this + 'th';
    }
    
    abs = abs % 10;
    if (abs === 1) { return this + 'st'; }
    if (abs === 2) { return this + 'nd'; }
    if (abs === 3) { return this + 'rd'; }
    
    return this + 'th';
};
356 Bytes in 3 ms with coderay