Small code: leap year

Geoff Canyon gcanyon at gmail.com
Tue Sep 23 10:11:56 EDT 2014


I came across http://exercism.io/about

It's an interesting site for developers to improve their skills with simple
problems and organized peer review. One of the simpler challenges is
writing a function to return whether a year is a leap year. I wrote this:

function isLeapYear Y
  return Y mod 4 = 0 and (Y mod 100 > 0 or Y mod 400 = 0)
end isLeapYear

If you wanted to be accepting of bad data you could:

function isLeapYear Y
  return Y is a number and Y mod 4 = 0 and (Y mod 100 > 0 or Y mod 400 = 0)
end isLeapYear



More information about the use-livecode mailing list