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