diff --git a/exercises/leap/example.js b/exercises/leap/example.js index ab09fa3301..ff90d1db35 100644 --- a/exercises/leap/example.js +++ b/exercises/leap/example.js @@ -1,4 +1,3 @@ - /** * @param {number} year * Numeric year. @@ -6,14 +5,5 @@ * @return {boolean} * Whether given year is a leap year. */ -class Year { - constructor(year) { - this.year = year; - } - - isLeap() { - return this.year % 400 === 0 || this.year % 4 === 0 && this.year % 100 !== 0; - } -} - -export default Year; +export const isLeap = year => + year % 400 === 0 || year % 4 === 0 && year % 100 !== 0; diff --git a/exercises/leap/leap.spec.js b/exercises/leap/leap.spec.js index 3dca703e0c..ed1df97a26 100644 --- a/exercises/leap/leap.spec.js +++ b/exercises/leap/leap.spec.js @@ -1,23 +1,19 @@ -import Year from './leap'; +import { isLeap } from './leap'; describe('A leap year', () => { test('year not divisible by 4: common year', () => { - const year = new Year(2015); - expect(year.isLeap()).toBeFalsy(); + expect(isLeap(2015)).toBeFalsy(); }); xtest('year divisible by 4, not divisible by 100: leap year', () => { - const year = new Year(2016); - expect(year.isLeap()).toBeTruthy(); + expect(isLeap(2016)).toBeTruthy(); }); xtest('year divisible by 100, not divisible by 400: common year', () => { - const year = new Year(2100); - expect(year.isLeap()).toBeFalsy(); + expect(isLeap(2100)).toBeFalsy(); }); xtest('year divisible by 400: leap year', () => { - const year = new Year(2000); - expect(year.isLeap()).toBeTruthy(); + expect(isLeap(2000)).toBeTruthy(); }); });