Check Leap Year

In this lab, your task is to implement a checkLeapYear function that takes a valid integer representing a year and returns true if the year is a leap year and false if it is not. Make sure to properly account for the century years.

Leap Year Rules

A year is a leap year if it meets the following criteria:

  1. A year is a leap year if it is evenly divisible by 4.
  2. A year is not a leap year if it is evenly divisible by 100, unless it is also evenly divisible by 400.

Examples

  • Year 2000: Divisible by 400, so it is a leap year -> true
  • Year 1900: Divisible by 100 but not by 400, so it is not a leap year -> false
  • Year 2020: Divisible by 4 and not by 100, so it is a leap year -> true
  • Year 2021: Not divisible by 4, so it is not a leap year -> false

Instructions

  1. Implement the checkLeapYear function in the codedamn package.
  2. The function should take an integer representing the year as input.
  3. The function should return a boolean:
    • true if the year is a leap year.
    • false if the year is not a leap year.

Function Signature

package codedamn func checkLeapYear(year int) bool { // Your code here }

Challenges

Your implementation will be tested against the following challenges:

Challenge 1: Test for Year 2024

  • Description: Verify that the checkLeapYear function correctly identifies the year 2024 as a leap year.
  • Input: 2024
  • Expected Output: true

Challenge 2: Test for Year 2100

  • Description: Verify that the checkLeapYear function correctly identifies the year 2100 as not a leap year.
  • Input: 2100
  • Expected Output: false

Challenge 3: Test for Year 2000

  • Description: Verify that the checkLeapYear function correctly identifies the year 2000 as a leap year.
  • Input: 2000
  • Expected Output: true

Challenge 4: Test for Year 1996

  • Description: Verify that the checkLeapYear function correctly identifies the year 1996 as a leap year.
  • Input: 1996
  • Expected Output: true

Guidelines

  • Make sure to create a proper helper function to validate if a year is a leap year or not instead of hardcoding the boolean values in the tests.
  • Ensure that your function handles all edge cases, especially century years.
  • The environment is already set up for you; you do not need to configure anything and can start coding immediately.
Adding your container request
Getting your dedicated container
Connecting to your container
Setting up your editor
Finalizing your playground
TerminalEditorBrowser