Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getPersons() {
- let personsArr = [];
- // Gabriel Peterson 24 g.p@gmail.com
- let persons = [
- ['Anna', 'Simpson', 22, 'anna@yahoo.com'],
- ['SoftUni'],
- ['Stephan', 'Johnson', 25],
- ['Gabriel', 'Peterson', 24, 'g.p@gmail.com'],
- ['Erol', 'Mehmed']
- ];
- class Person {
- constructor(firstName, lastName, age, email) {
- this.firstName = firstName;
- this.lastName = lastName;
- this.age = age;
- this.email = email;
- };
- toString() {
- let person = `${this.firstName} ${this.lastName} (age: ${this.age}, email: ${this.email})`;
- return person;
- };
- toString2() {
- let person = `${this.firstName} ${this.lastName} (age: ${this.age})`;
- return person;
- };
- toString3() {
- let person = `${this.firstName} ${this.lastName}`;
- return person;
- };
- toString4() {
- let person = this.firstName;
- return person;
- };
- };
- for (let arr of persons) {
- let firstName = arr[0];
- let lastName = arr[1];
- let age = arr[2];
- let email = arr[3];
- if (arr.length === 4) {
- let person = new Person(firstName, lastName, age, email);
- personsArr.push(person.toString());
- } else if (arr.length === 3) {
- let person = new Person(firstName, lastName, age);
- personsArr.push(person.toString2());
- } else if (arr.length === 2) {
- let person = new Person(firstName, lastName);
- personsArr.push(person.toString3());
- } else if (arr.length === 1) {
- let person = new Person(firstName);
- personsArr.push(person.toString4());
- }
- }
- // console.log(personsArr);
- return personsArr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement