-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathe-array.js
49 lines (39 loc) · 959 Bytes
/
e-array.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
const data = [
['Marcus Aurelius', '121-04-26', 'Rome'],
['Commodus Antoninus', '161-08-31', 'Rome'],
['Victor Glushkov', '1923-08-24', 'Rostov on Don'],
['Ibn Arabi', '1165-11-16', 'Murcia'],
['Mao Zedong', '1893-12-26', 'Shaoshan'],
['Rene Descartes', '1596-03-31', 'La Haye en Touraine']
];
class Person {
get name() {
return this[0];
}
get birth() {
return this[1];
}
get city() {
return this[2];
}
get age() {
const difference = new Date() - new Date(this.birth);
return Math.floor(difference / 31536000000);
}
toString() {
return this.name + ' age is ' + this.age;
}
}
const query = (person) => (
person.name !== '' &&
person.age > 18 &&
person.city === 'Rome'
);
console.dir(data);
data.forEach((person) => {
Object.setPrototypeOf(person, Person.prototype);
// person.__proto__ = Person.prototype
});
const res = data.filter(query);
console.log(res.join('\n'));