Skip to content

Instantly share code, notes, and snippets.

@MtnBiker
Created February 13, 2014 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MtnBiker/8968769 to your computer and use it in GitHub Desktop.
Save MtnBiker/8968769 to your computer and use it in GitHub Desktop.
def calculate_age (age_in_seconds)
seconds_in_year = 365*24*3600
seconds_in_month = seconds_in_year/12
years = age_in_seconds/seconds_in_year # this gets truncated which is fine
months = (age_in_seconds - (years * seconds_in_year))/seconds_in_month
puts "I’m #{years} years and #{months} months old."
[years, months] # following your suggestion to return an array
end
ageArr1 = calculate_age 979000000
ageArr2 = calculate_age 2158493738
ageArr3 = calculate_age 246144023
ageArr4 = calculate_age 1270166272
ageArr5 = calculate_age 1025600095
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment