Skip to main content
added 10 characters in body
Source Link
Mr. Llama
  • 2.4k
  • 20
  • 20

Ruby, 57

Ruby, 60

It's not as good as the Perl entry, but I figured I'd work on my Ruby skills.

def o(n)n.to_s+%w{th st nd rd}[n/10==1||n%10>310%10==1||n%10>3?0:n%10]end

Function takes one integer argument, n, and returns a string as the ordinal form.

Works according to the following logic:
If the tens digit is a 1 or the ones digit is greater than 3 use the suffix 'th'; otherwise find the suffix from the array ['th', 'st', 'nd', 'rd'] using the final digit as the index.

Ruby, 57

It's not as good as the Perl entry, but I figured I'd work on my Ruby skills.

def o(n)n.to_s+%w{th st nd rd}[n/10==1||n%10>3?0:n%10]end

Function takes one integer argument, n, and returns a string as the ordinal form.

Works according to the following logic:
If the tens digit is a 1 or the ones digit is greater than 3 use the suffix 'th'; otherwise find the suffix from the array ['th', 'st', 'nd', 'rd'] using the final digit as the index.

Ruby, 60

It's not as good as the Perl entry, but I figured I'd work on my Ruby skills.

def o(n)n.to_s+%w{th st nd rd}[n/10%10==1||n%10>3?0:n%10]end

Function takes one integer argument, n, and returns a string as the ordinal form.

Works according to the following logic:
If the tens digit is a 1 or the ones digit is greater than 3 use the suffix 'th'; otherwise find the suffix from the array ['th', 'st', 'nd', 'rd'] using the final digit as the index.

Source Link
Mr. Llama
  • 2.4k
  • 20
  • 20

Ruby, 57

It's not as good as the Perl entry, but I figured I'd work on my Ruby skills.

def o(n)n.to_s+%w{th st nd rd}[n/10==1||n%10>3?0:n%10]end

Function takes one integer argument, n, and returns a string as the ordinal form.

Works according to the following logic:
If the tens digit is a 1 or the ones digit is greater than 3 use the suffix 'th'; otherwise find the suffix from the array ['th', 'st', 'nd', 'rd'] using the final digit as the index.