you are here: codestackercodes [RSS] → tag number [RSS]

turning numbers into ordinals

def ordinal(rank) 
  result = case rank 
    when 4..20: h(rank) + "th" 
    else 
    result = case (rank.modulo(10)) 
      when 1: h(rank) + "st" 
      when 2: h(rank) + "nd" 
      when 3: h(rank) + "rd" 
      else h(rank) + "th" 
    end 
  end 
  result 
end
Displaying 1 Code