Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type User = {
- name: string;
- age: number;
- birthday?: string|Date;
- };
- const prettyPrintWilder = (users: User[]) => {
- console.log("########################");
- users.map((el) => {
- console.log(`${el.name} is ${el.age} years old`);
- });
- console.log("########################");
- };
- const wilders: User[] = [];
- const user1 = { name: "Pierre", age: 23 };
- const user2 = { name: "Paul", age: calculateAge("10/02/1990") };
- const user3 = { name: "Jacques", age: 25 };
- wilders.push(user1);
- wilders.push(user2);
- wilders.push(user3);
- prettyPrintWilder(wilders);
- function calculateAge(birthday:string){
- let birth = new Date(birthday)
- let yearBirth = birth.getFullYear();
- let today = 2020;
- return today - yearBirth;
- }
Advertisement
Add Comment
Please, Sign In to add comment