Files
freeCodeCamp/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/leap-year.md
Bhanu Pratap Singh Rathore 79394d141f feat(interview-prep): Converting and transferring Rosetta problems (#35487)
* feat(interview-prep): Converting and transferring Rosetta problems

* feat(interview-prep): Fixing challenges

* fix(challenges): Added code tags

* Update knight's-tour.md

Moved text to instructions section and fixed a small typo.

* feat(interview-prep): Update description of Knight's tour

Co-Authored-By: NitronR <bhanur05@gmail.com>

* feat(interview-prep): Update description of Kaprekar numbers

Co-Authored-By: NitronR <bhanur05@gmail.com>

* feat(inteview-prep): Kaprekar numbers description

Added <code> tags.

* fix(interview-prep): Update description Kaprekar Numbers

Co-Authored-By: NitronR <bhanur05@gmail.com>

* fix(interview-prep): Added code tags Kaprekar numbers

Co-Authored-By: NitronR <bhanur05@gmail.com>
2019-03-21 11:52:35 +05:30

2.1 KiB

id, title, challengeType
id title challengeType
5a23c84252665b21eecc7ede Leap year 5

Description

Determine whether a given year is a leap year in the Gregorian calendar.

Instructions

Tests

tests:
  - text: <code>isLeapYear</code> should be a function.
    testString: assert(typeof isLeapYear == 'function', '<code>isLeapYear</code> should be a function.');
  - text: <code>isLeapYear()</code> should return a boolean.
    testString: assert(typeof isLeapYear(2018) == 'boolean', '<code>isLeapYear()</code> should return a boolean.');
  - text: <code>isLeapYear(2018)</code> should return <code>false</code>.
    testString: assert.equal(isLeapYear(2018), false, '<code>isLeapYear(2018)</code> should return <code>false</code>.');
  - text: <code>isLeapYear(2016)</code> should return <code>true</code>.
    testString: assert.equal(isLeapYear(2016), true, '<code>isLeapYear(2016)</code> should return <code>true</code>.');
  - text: <code>isLeapYear(2000)</code> should return <code>true</code>.
    testString: assert.equal(isLeapYear(2000), true, '<code>isLeapYear(2000)</code> should return <code>true</code>.');
  - text: <code>isLeapYear(1900)</code> should return <code>false</code>.
    testString: assert.equal(isLeapYear(1900), false, '<code>isLeapYear(1900)</code> should return <code>false</code>.');
  - text: <code>isLeapYear(1996)</code> should return <code>true</code>.
    testString: assert.equal(isLeapYear(1996), true, '<code>isLeapYear(1996)</code> should return <code>true</code>.');
  - text: <code>isLeapYear(1800)</code> should return <code>false</code>.
    testString: assert.equal(isLeapYear(1800), false, '<code>isLeapYear(1800)</code> should return <code>false</code>.');

Challenge Seed

function isLeapYear(year) {
  // Good luck!
}

Solution

function isLeapYear (year) {
  return (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0);
};