Array.prototype.filter()
1. Filter the list of inventors for those who were born in the 1500's.
const fifteen = inventors.filter(
(inventor) => inventor.year >= 1500 && inventor.year < 1600
);
console.table(fifteen);
2. Array.prototype.map()
Give us an array of the inventor's first and last names.
const fullNames = inventors.map(
(inventor) => `${inventor.first} ${inventor.last}`
);
console.log(fullNames);
3.Array.prototype.sort()
Sort the inventors by birthdate, oldest to youngest
const ordered = inventors.sort((a, b) => (a.year > b.year ? 1 : -1));
console.table(ordered);
4.Array.prototype.reduce()
How many years did all the inventors live?
const totalYears = inventors.reduce((total, inventor) => {
return total + (inventor.passed — inventor.year);
}, 0);
console.log(totalYears);
5. Sort the inventors by years lived
const oldest = inventors.sort(function (a, b) {
const lastInventor = a.passed — a.year;
const nextInventor = b.passed — b.year;
return lastInventor > nextInventor ? -1 : 1;
});
console.table(oldest);
6. create a list of Boulevards in Paris that contain ‘de’ anywhere in the name
https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
const category = document.querySelector(‘.mw-category’);
const links = Array.from(category.querySelectorAll(‘a’));
const de = links
.map(link => link.textContent)
.filter(streetName => streetName.includes(‘de’));
7. sort Exercise
Sort the people alphabetically by their last name