forked from Bashkatov-spb/first-phase-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask1.js
62 lines (59 loc) · 1.74 KB
/
task1.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
50
51
52
53
54
55
56
57
58
59
60
61
62
const data = [
{
firstName: 'Gabriel',
lastName: 'X.',
country: 'Monaco',
continent: 'Europe',
age: 49,
language: 'PHP',
},
{
firstName: 'Odval',
lastName: 'F.',
country: 'Mongolia',
continent: 'Asia',
age: 38,
language: 'Python',
},
{
firstName: 'Emilija',
lastName: 'S.',
country: 'Lithuania',
continent: 'Europe',
age: 19,
language: 'Python',
},
{
firstName: 'Sou',
lastName: 'B.',
country: 'Japan',
continent: 'Asia',
age: 49,
language: 'PHP',
},
{
firstName: 'John',
lastName: 'L.',
country: 'Tokio',
continent: 'Asia',
age: 49,
language: 'Java',
},
];
// Необходимо вернуть массив, содержащий самого старшего человека в списке. Если несколько людей имеют одинаковый наибольший возраст,
// то нужно вернуть массив, содержащий их всех.
const getMostSenior = (data) => {
// let result = data.filter((el) => el.age === Math.max(...data.map(el => el.age));
const max = Math.max(...data.map((el) => el.age));
const result = data.filter((el) => el.age === max);
return result;
// arr.reduce((prev, current) => (prev.b > current.b ? prev : current), [])
// твой код тут
};
const result = getMostSenior(data);
console.log(result);
// [
// { firstName: 'Gabriel', lastName: 'X.', country: 'Monaco', continent: 'Europe', age: 49, language: 'PHP' },
// { firstName: 'Sou', lastName: 'B.', country: 'Japan', continent: 'Asia', age: 49, language: 'PHP' },
// { firstName: 'John', lastName: 'L.', country: 'Tokio', continent: 'Asia', age: 49, language: 'Java' },
// ]