Skip to content

Instantly share code, notes, and snippets.

@jlbruno

jlbruno/ordinal.js

Last active Feb 16, 2021
Embed
What would you like to do?
Javascript Ordinal Numbers
// found here http://forums.shopify.com/categories/2/posts/29259
var getGetOrdinal = function(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}
@Oluwasetemi

This comment has been minimized.

Copy link

@Oluwasetemi Oluwasetemi commented Oct 23, 2018

cool!!

var convert = (n )  => {
  let res = '';  
  if (n === 0) return res = String(n)
  
  switch (n % 10) {
    case 1:
      if ( n === 11)  return res = `${n}th`;
       res = `${n}st`;
      break;
    case 2:
      if ( n === 12)  return res = `${n}th`;
       res = `${n}nd`;
      break;
    case 3:
      if ( n === 13)  return res = `${n}th`;
       res = `${n}rd`;
      break;
    default:
       res = `${n}th`;
      break;
  }
  return res
}

this make me feel bad 😢 too long

@aacassandra

This comment has been minimized.

Copy link

@aacassandra aacassandra commented Jul 12, 2019

yo save my time bro!! very cool!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment