Skip to content

Instantly share code, notes, and snippets.

@JosephDunivan
Last active June 15, 2022 10:39
Show Gist options
  • Save JosephDunivan/17805d57b50a081440223ab306827bc0 to your computer and use it in GitHub Desktop.
Save JosephDunivan/17805d57b50a081440223ab306827bc0 to your computer and use it in GitHub Desktop.
centuryFromYear in Ruby
def centuryFromYear(year)
#solution requires us find out if the century has a remainder of 0 or not.
#we can remove the remainder from the year to get a clean number since centuries happen in multiples of 100
if (year % 100) == 0
year/100
else
(year - (year % 100))/100 + 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment