mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-07-13 11:46:03 +09:00
+3
-1
@@ -2,7 +2,9 @@
|
||||
|
||||
Create a function that determines whether or not a given year is a leap year. Leap years are determined by the following rules:
|
||||
|
||||
>There is a leap year every year whose number is perfectly divisible by four - except for years evenly divisible by 100, which are not leap years unless evenly divisible by 400. The second part of the rule affects century years. For example; the century years 1600 and 2000 are leap years, but the century years 1700, 1800, and 1900 are not.
|
||||
> Leap years are years divisible by four (like 1984 and 2004). However, years divisible by 100 are not leap years (such as 1800 and 1900) unless they are divisible by 400 (like 1600 and 2000, which were in fact leap years). (Yes, it's all pretty confusing)
|
||||
>
|
||||
> -- <cite>[Learn to Program](https://pine.fm/LearnToProgram/chap_06.html) by Chris Pine</cite>
|
||||
|
||||
```javascript
|
||||
leapYears(2000) // is a leap year: returns true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var leapYears = function() {
|
||||
const leapYears = function() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -1,22 +1,22 @@
|
||||
const leapYears = require('./leapYears')
|
||||
const leapYears = require("./leapYears");
|
||||
|
||||
describe('leapYears', () => {
|
||||
test('works with non century years', () => {
|
||||
describe("leapYears", () => {
|
||||
test("works with non century years", () => {
|
||||
expect(leapYears(1996)).toBe(true);
|
||||
});
|
||||
test.skip('works with non century years', () => {
|
||||
expect(leapYears(1997)).toBe(false);
|
||||
xit("works with non century years", function () {
|
||||
expect(leapYears(1997)).toEqual(false);
|
||||
});
|
||||
test.skip('works with ridiculously futuristic non century years', () => {
|
||||
expect(leapYears(34992)).toBe(true);
|
||||
xit("works with ridiculously futuristic non century years", function () {
|
||||
expect(leapYears(34992)).toEqual(true);
|
||||
});
|
||||
test.skip('works with century years', () => {
|
||||
expect(leapYears(1900)).toBe(false);
|
||||
xit("works with century years", function () {
|
||||
expect(leapYears(1900)).toEqual(false);
|
||||
});
|
||||
test.skip('works with century years', () => {
|
||||
expect(leapYears(1600)).toBe(true);
|
||||
xit("works with century years", function () {
|
||||
expect(leapYears(1600)).toEqual(true);
|
||||
});
|
||||
test.skip('works with century years', () => {
|
||||
expect(leapYears(700)).toBe(false);
|
||||
xit("works with century years", function () {
|
||||
expect(leapYears(700)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user