-
-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Labels
enhancementNew feature or requestNew feature or request
Description
This is a common side exercise, probably because it looks (and is) pretty simple. Some people even attempt this before Two Fer.
Every solution, without exception, looks like this:
func IsLeapYear(year int) bool {
return (year%4 == 0 && year%100 != 0) || year%400 == 0
}(or some equivalent Boolean transformation). Fine as far as it goes, but there's a missed opportunity to make this code clear, simple, and readable, in a way that matches the English description of the problem. Something along these lines:
func IsLeapYear(year int) bool {
if year%4 != 0 {
return false
}
if year%400 == 0 {
return true
}
if year%100 == 0 {
return false
}
return true
}(Not saying this is the perfect solution, but it illustrates what I'm talking about.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request