parent
ba2ca7cfdd
commit
7e5ccebcdf
5 changed files with 23 additions and 21 deletions
@ -1,21 +1,21 @@ |
|||||||
module.exports = { |
module.exports = { |
||||||
age: age, |
age: age, |
||||||
}; |
} |
||||||
|
|
||||||
function age() { |
function age() { |
||||||
let birthdate = new Date(2002, 8, 29); |
let birthdate = new Date(2002, 8, 29) |
||||||
let now = new Date(); |
let now = new Date() |
||||||
|
|
||||||
let age = now.getFullYear() - birthdate.getFullYear(); |
let age = now.getFullYear() - birthdate.getFullYear() |
||||||
|
|
||||||
if (now.getMonth() < birthdate.getMonth()) { |
if (now.getMonth() < birthdate.getMonth()) { |
||||||
age--; |
age-- |
||||||
} |
} |
||||||
if ( |
if ( |
||||||
birthdate.getMonth() === now.getMonth() && |
birthdate.getMonth() === now.getMonth() && |
||||||
now.getDate() < birthdate.getDate() |
now.getDate() < birthdate.getDate() |
||||||
) { |
) { |
||||||
age--; |
age-- |
||||||
} |
} |
||||||
return age; |
return age |
||||||
} |
} |
||||||
|
@ -1,10 +1,10 @@ |
|||||||
const assert = require("chai").assert; |
const assert = require('chai').assert |
||||||
const me = require("../src/me"); |
const me = require('../src/me') |
||||||
|
|
||||||
describe("me", () => { |
describe('me', () => { |
||||||
describe("age", () => { |
describe('age', () => { |
||||||
it("should return a positive number", () => { |
it('should return a positive number', () => { |
||||||
assert.isAbove(me.age(), 0); |
assert.isAbove(me.age(), 0) |
||||||
}); |
}) |
||||||
}); |
}) |
||||||
}); |
}) |
||||||
|
Loading…
Reference in new issue