Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions 04 - Array Cardio Day 1/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,49 @@

// Array.prototype.filter()
// 1. Filter the list of inventors for those who were born in the 1500's
inventors.filter(el => { el.year >= 1500 && el.year < 1600 })

// Array.prototype.map()
// 2. Give us an array of the inventors' first and last names
inventors.map(i => `${i.first} ${i.last}`)

// Array.prototype.sort()
// 3. Sort the inventors by birthdate, oldest to youngest
inventors.sort((a, b) => a.year - b.year)

// Array.prototype.reduce()
// 4. How many years did all the inventors live?
//861
inventors.reduce((total, i) => {
let yearsLived = i.passed - i.year;
return total + yearsLived;
}, 0);

// 5. Sort the inventors by years lived
inventors.sort((a, b) => {
return (a.passed - a.year) > (b.passed - b.year) ? 1 : -1
})

// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
Array.from(document.querySelectorAll('li a')).map(el => el.title).filter(title => /de/.test(title))


// 7. sort Exercise
// Sort the people alphabetically by last name
people.sort()

// 8. Reduce Exercise
// Sum up the instances of each of these
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];

data.reduce((total, el) => {
if (!total[el]) total[el] = 0;

total[el] += 1
return total
}, {})

</script>
</body>
</html>