-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_4.js
More file actions
44 lines (40 loc) · 1.89 KB
/
script_4.js
File metadata and controls
44 lines (40 loc) · 1.89 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 entrepreneurs = [
{ first: 'Steve', last: 'Jobs', year: 1955 },
{ first: 'Oprah', last: 'Winfrey', year: 1954 },
{ first: 'Bill', last: 'Gates', year: 1955 },
{ first: 'Sheryl', last: 'Sandberg', year: 1969 },
{ first: 'Mark', last: 'Zuckerberg', year: 1984 },
{ first: 'Beyonce', last: 'Knowles', year: 1981 },
{ first: 'Jeff', last: 'Bezos', year: 1964 },
{ first: 'Diane', last: 'Hendricks', year: 1947 },
{ first: 'Elon', last: 'Musk', year: 1971 },
{ first: 'Marissa', last: 'Mayer', year: 1975 },
{ first: 'Walt', last: 'Disney', year: 1901 },
{ first: 'Larry', last: 'Page', year: 1973 },
{ first: 'Jack', last: 'Dorsey', year: 1976 },
{ first: 'Evan', last: 'Spiegel', year: 1990 },
{ first: 'Brian', last: 'Chesky', year: 1981 },
{ first: 'Travis', last: 'Kalanick', year: 1976 },
{ first: 'Marc', last: 'Andreessen', year: 1971 },
{ first: 'Peter', last: 'Thiel', year: 1967 }
];
// 1) Filter this list to show entrepreneurs born in the 1970s
console.log("1) Entrepreneurs born in the 1970s:");
const seventies = entrepreneurs.filter(e => e.year >= 1970 && e.year < 1980);
console.log(seventies);
// 2) Output an array containing the first and last names of the entrepreneurs
console.log("\n2) Array of first and last names:");
const names = entrepreneurs.map(e => `${e.first} ${e.last}`);
console.log(names);
// 3) How old would each inventor be today?
const currentYear = new Date().getFullYear();
console.log(`\n3) How old would each inventor be in ${currentYear}?`);
const ages = entrepreneurs.map(e => ({
name: `${e.first} ${e.last}`,
age: currentYear - e.year
}));
console.log(ages);
// 4) Sort the entrepreneurs alphabetically by last name
console.log("\n4) Entrepreneurs sorted alphabetically by last name:");
const sortedByLast = [...entrepreneurs].sort((a, b) => a.last.localeCompare(b.last));
console.log(sortedByLast);