Skip to content

Commit acaa2a3

Browse files
committed
finish array bootcamp 1
1 parent 5d0e821 commit acaa2a3

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

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

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,93 @@
3737

3838
// Array.prototype.filter()
3939
// 1. Filter the list of inventors for those who were born in the 1500's
40+
const inventorsBornInFifteenHundreds = inventors.filter((inventor) => inventor.year > 1500 && inventor.year < 1600)
41+
console.log("inventorsBornInFifteenHundreds",inventorsBornInFifteenHundreds)
4042

4143
// Array.prototype.map()
4244
// 2. Give us an array of the inventors first and last names
45+
const inventorsFirstLastNames = inventors.map((inventor) => `${inventor.first} ${inventor.last}`)
46+
console.log("inventorsFirstLastNames",inventorsFirstLastNames)
4347

4448
// Array.prototype.sort()
4549
// 3. Sort the inventors by birthdate, oldest to youngest
50+
const inventorsBirthDateOldestToYoungest = inventors.sort((a, b) => a.year > b.year ? 1 : -1)
51+
console.log("inventorsBirthDateOldestToYoungest",inventorsBirthDateOldestToYoungest)
4652

4753
// Array.prototype.reduce()
4854
// 4. How many years did all the inventors live all together?
55+
const inventorsAgeCombined = inventors.reduce((prev, inventor) => ((inventor.passed - inventor.year) + prev), 0)
56+
console.log(inventorsAgeCombined)
4957

5058
// 5. Sort the inventors by years lived
59+
const inventorsSortedByYearsLived = inventors.sort((a, b) => ((a.passed - a.year) < (b.passed - b.year) ? 1 : -1))
60+
console.log("inventorsSortedByYearsLived",inventorsSortedByYearsLived)
61+
console.log("inventorsSortedByYearsLived - with age",inventorsSortedByYearsLived.map((i) => {i["age"] = i.passed - i.year; return i}))
5162

5263
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
5364
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
54-
65+
// const boulevards = [
66+
// "Boulevards of Paris",
67+
// "City walls of Paris",
68+
// "Thiers wall",
69+
// "Wall of Charles V",
70+
// "Wall of Philip II Augustus",
71+
// "City gates of Paris",
72+
// "Haussmann's renovation of Paris",
73+
// "Boulevards of the Marshals",
74+
// "Boulevard Auguste-Blanqui",
75+
// "Boulevard Barbès",
76+
// "Boulevard Beaumarchais",
77+
// "Boulevard de l'Amiral-Bruix",
78+
// "Boulevard Mortier",
79+
// "Boulevard Poniatowski",
80+
// "Boulevard Soult",
81+
// "Boulevard des Capucines",
82+
// "Boulevard de la Chapelle",
83+
// "Boulevard de Clichy",
84+
// "Boulevard du Crime",
85+
// "Boulevard du Général-d'Armée-Jean-Simon",
86+
// "Boulevard Haussmann",
87+
// "Boulevard de l'Hôpital",
88+
// "Boulevard des Italiens",
89+
// "Boulevard Lefebvre",
90+
// "Boulevard de la Madeleine",
91+
// "Boulevard de Magenta",
92+
// "Boulevard Malesherbes",
93+
// "Boulevard Marguerite-de-Rochechouart",
94+
// "Boulevard Montmartre",
95+
// "Boulevard du Montparnasse",
96+
// "Boulevard Raspail",
97+
// "Boulevard Richard-Lenoir",
98+
// "Boulevard Saint-Germain",
99+
// "Boulevard Saint-Michel",
100+
// "Boulevard de Sébastopol",
101+
// "Boulevard de Strasbourg",
102+
// "Boulevard du Temple",
103+
// "Boulevard Voltaire",
104+
// "Boulevard de la Zone"
105+
// ]
106+
// const deBoulevards = boulevards.filter((boulevard) => /de/i.test(boulevard))
107+
// console.log("deBoulevards",deBoulevards)
55108

56109
// 7. sort Exercise
57110
// Sort the people alphabetically by last name
111+
const sortedPeople = people.sort((a, b) => a.split(",")[0] > b.split(",")[0] ? 1 : -1)
112+
console.log("sortedPeople",sortedPeople)
113+
58114

59115
// 8. Reduce Exercise
60116
// Sum up the instances of each of these
61117
const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ];
118+
// const reducedExercise = data.reduce((vehicleCounts, vehicle) => (!vehicleCounts[vehicle] ? vehicleCounts[vehicle] = 1 : vehicleCounts[vehicle] += 1), {})
119+
const reducedExercise = data.reduce((vehicleCounts, vehicle) => {
120+
if(!vehicleCounts[vehicle]){
121+
vehicleCounts[vehicle] = 1
122+
}else{
123+
vehicleCounts[vehicle] += 1
124+
}
125+
return vehicleCounts}, {})
126+
console.log("reducedExercise", reducedExercise)
62127

63128
</script>
64129
</body>

0 commit comments

Comments
 (0)