Nodejs Utililty Methods Number to Ordinal Format

List of utility methods to do Number to Ordinal Format

Description

The list of methods to do Number to Ordinal Format are organized into topic(s).

Method

toOrdinal()
Number.prototype.toOrdinal = function() {
  var n = this % 100;
  var suffix = ["th", "st", "nd", "rd", "th"];
  var ord = n < 21 ? (n < 4 ? suffix[n] : suffix[0]) : (n % 10 > 4 ? suffix[0] : suffix[n % 10]);
  return this + ord;
};
toOrdinal()
Number.prototype.toOrdinal = function() {
  var s = ['th','st','nd','rd'];
  var v = this%100;
  return this + (s[(v-20)%10]||s[v]||s[0]);
};
toOrdinal()
Number.prototype.toOrdinal = function() {
    var n = this % 100,
        suffix = ['th', 'st', 'nd', 'rd', 'th'],
        ord = n < 21 ? (n < 4 ? suffix[n] : suffix[0]) : (n % 10 > 4 ? suffix[0] : suffix[n % 10]);
    return this + ord;
};
toOrdinal()
Number.prototype.toOrdinal = function() {
    var n,
        s = ["th","st","nd","rd"],
        v = n % 100;
    return n + (s[(v - 20) % 10] || s[v] || s[0]);
};