Remove person example
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "yearbook",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"test": "vitest"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/stevekinney/testing-javascript.git"
|
|
||||||
},
|
|
||||||
"author": "Steve Kinney <hello@stevekinney.net>",
|
|
||||||
"license": "MIT",
|
|
||||||
"bugs": {
|
|
||||||
"url": "https://github.com/stevekinney/testing-javascript/issues"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/stevekinney/testing-javascript#readme",
|
|
||||||
"devDependencies": {
|
|
||||||
"@vitest/ui": "^2.1.1",
|
|
||||||
"vite": "^5.4.5",
|
|
||||||
"vitest": "^2.1.1"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
* A person in the yearbook.
|
|
||||||
* @class Person
|
|
||||||
* @param {number} id
|
|
||||||
* @param {string} firstName
|
|
||||||
* @param {string} lastName
|
|
||||||
* @param {string} dateOfBirth
|
|
||||||
*/
|
|
||||||
export class Person {
|
|
||||||
static id = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A person in the yearbook.
|
|
||||||
* @param {string} firstName
|
|
||||||
* @param {string} lastName
|
|
||||||
* @param {string} dateOfBirth
|
|
||||||
*/
|
|
||||||
constructor(firstName, lastName, dateOfBirth) {
|
|
||||||
this.id = ++Person.id;
|
|
||||||
this.firstName = firstName;
|
|
||||||
this.lastName = lastName;
|
|
||||||
this.dateOfBirth = dateOfBirth;
|
|
||||||
}
|
|
||||||
|
|
||||||
get fullName() {
|
|
||||||
return `${this.firstName} ${this.lastName}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
get age() {
|
|
||||||
const today = new Date();
|
|
||||||
const birthDate = new Date(this.dateOfBirth);
|
|
||||||
|
|
||||||
let age = today.getFullYear() - birthDate.getFullYear();
|
|
||||||
const month = today.getMonth() - birthDate.getMonth();
|
|
||||||
|
|
||||||
if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) {
|
|
||||||
age--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return age;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
|
||||||
import { Person } from './person';
|
|
||||||
|
|
||||||
describe('Person', () => {
|
|
||||||
it('should be an instance of a Person', () => {
|
|
||||||
const person = new Person('John', 'Doe', '2000-01-01');
|
|
||||||
expect(person).toBeInstanceOf(Person);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user