Visitar URL original
04 completed · wesbos/JavaScript30@06a50a3 · GitHub
Skip to content

Commit 06a50a3

Browse files
author
John Carlo Buenaflor
committed
04 completed
1 parent 462fb0e commit 06a50a3

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎04 - Array Cardio Day 1/index-START.html‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,42 @@
3333

3434
// Array.prototype.filter()
3535
// 1. Filter the list of inventors for those who were born in the 1500's
36+
const bornInFifteenHundreds = inventors.filter( inventor => inventor.year >= 1500 && inventor.year < 1600)
3637

3738
// Array.prototype.map()
3839
// 2. Give us an array of the inventors' first and last names
40+
const firstLastNames = inventors.map( inventor => ({first: inventor.first, last: inventor.last}))
3941

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

4346
// Array.prototype.reduce()
4447
// 4. How many years did all the inventors live?
48+
const totalYears = inventors.reduce( (total, inventor) => inventor.passed - inventor.year + total, 0)
4549

4650
// 5. Sort the inventors by years lived
51+
inventors.sort( (a, b) => (a.passed - a.year) - (b.passed - b.year) )
4752

4853
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4954
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
55+
const blvdsDOM = document.querySelectorAll('.mw-category-group li')
56+
const blvds = Array.from(blvdsDOM).map(b => b.innerText)
57+
const blvdsDE = blvds.filter(b => b.toLowerCase().includes('de'))
5058

5159

5260
// 7. sort Exercise
5361
// Sort the people alphabetically by last name
62+
people.sort()
5463

5564
// 8. Reduce Exercise
5665
// Sum up the instances of each of these
5766
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
58-
67+
const instances = data.reduce( (prev, curr) => {
68+
if (!prev[curr]) prev[curr] = 1
69+
else prev[curr] += 1
70+
return prev
71+
}, {})
5972
</script>
6073
</body>
6174
</html>

0 commit comments

Comments
 (0)