-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombined.js
More file actions
44 lines (37 loc) · 1.44 KB
/
combined.js
File metadata and controls
44 lines (37 loc) · 1.44 KB
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
const companies = [
{name: "Company One", category: "Finance", start: 1981, end: 2003},
{name: "Company Two", category: "Retail", start: 1992, end: 2008},
{name: "Company Three", category: "Auto", start: 1999, end: 2007},
{name: "Company Four", category: "Retail", start: 1989, end: 2010},
{name: "Company Five", category: "Technology", start: 2009, end: 2014},
{name: "Company Six", category: "Finance", start: 1987, end: 2010},
{name: "Company Seven", category: "Auto", start: 1986, end: 1996},
{name: "Company Eight", category: "Technology", start: 2011, end: 2016},
{name: "Company Nine", category: "Retail", start: 1981, end: 1989}
];
const ages = [33, 12, 20, 16, 5, 54, 21, 44, 61, 13, 15, 45, 25, 64, 32];
//combined map, sort, filter, reduce
const combined = companies.map(function(company) {
return {
name: company.name,
category: company.category,
start: company.start,
end: company.end,
age: ages.filter(function(age) {
return age >= company.start && age <= company.end;
})
};
}).sort(function(a, b) {
return a.name.localeCompare(b.name);
}).filter(function(company) {
return company.age.length > 0;
}).reduce(function(a, b) {
return a + b.age.length;
}, 0);
// console.log(combined);
const combinedAges = ages
.map(age => age * 2)
.filter(age => age > 30)
.sort((a, b) => a - b)
.reduce((a, b) => a + b, 0);
console.log(combinedAges);