Skip to content

Commit 0c23aca

Browse files
author
Carlos Filoteo
committed
Add solution for project 04.
1 parent 4e6a9aa commit 0c23aca

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

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

3434
// Array.prototype.filter()
3535
// 1. Filter the list of inventors for those who were born in the 1500's
36+
const inventorsBorn1500 = inventors.filter(person => person.year >= 1500 && person.year < 1599)
37+
// console.table(inventorsBorn1500)
3638

3739
// Array.prototype.map()
3840
// 2. Give us an array of the inventors' first and last names
41+
const fullNames = inventors.map(inventor => `${ inventor.first } ${ inventor.last }`)
42+
// console.log(fullNames)
3943

4044
// Array.prototype.sort()
4145
// 3. Sort the inventors by birthdate, oldest to youngest
46+
const birthdaySort = inventors.sort((a, b) => a.year > b.year ? 1 : -1)
47+
// console.table(birthdaySort)
4248

4349
// Array.prototype.reduce()
4450
// 4. How many years did all the inventors live?
51+
const totalYears = inventors.reduce((total, {year, passed}) => {return total + (passed - year)}, 0)
52+
// console.log(totalYears)
4553

4654
// 5. Sort the inventors by years lived
55+
const sortByYearsLived = inventors.sort((a, b) => (a.passed - a.year) > (b.passed - b.year) ? -1 : 1)
56+
// console.table(sortByYearsLived)
4757

4858
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
4959
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
5060

5161

5262
// 7. sort Exercise
5363
// Sort the people alphabetically by last name
64+
const alphaByLastName = people.sort((a, b) => {
65+
const [aLast, ] = a.split(', '),
66+
[bLast, ] = b.split(', ')
67+
return aLast > bLast ? 1 : -1
68+
})
69+
// console.log(alphaByLastName)
5470

5571
// 8. Reduce Exercise
5672
// Sum up the instances of each of these
5773
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
58-
74+
const transportation = data.reduce((options, transport) => {
75+
if(!options[transport]) options[transport] = 0
76+
options[transport]++
77+
return options
78+
}, {})
79+
// console.log(transportation)
5980
</script>
6081
</body>
6182
</html>

0 commit comments

Comments
 (0)