Skip to content

Commit 5218a11

Browse files
committed
Complete
1 parent 36ebed0 commit 5218a11

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,60 @@
3838

3939
// Array.prototype.filter()
4040
// 1. Filter the list of inventors for those who were born in the 1500's
41+
// const born = inventors.filter((i) => i.year < 1600 && i.year > 1499);
42+
// console.log(born);
4143

4244
// Array.prototype.map()
4345
// 2. Give us an array of the inventors first and last names
46+
// const mappedArr = inventors.map((i) => [i.first, i.last]);
47+
// console.log(mappedArr);
48+
4449

4550
// Array.prototype.sort()
4651
// 3. Sort the inventors by birthdate, oldest to youngest
52+
// const sorted = inventors.sort((a,b) => a.year > b.year ? 1 : -1);
53+
// console.table(sorted);
4754

4855
// Array.prototype.reduce()
4956
// 4. How many years did all the inventors live all together?
57+
// const totalYears = inventors.reduce((total, inventor) => total + (inventor.passed - inventor.year),0);
58+
// console.log(totalYears);
5059

5160
// 5. Sort the inventors by years lived
61+
// const sortYears = inventors.sort((a,b) => a.passed - a.year > b.passed - b.year ? -1 : 1);
62+
// console.table(sortYears);
5263

5364
// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name
54-
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
65+
//https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
66+
// const category = document.querySelector(".mw-category");
67+
// const links = [...category.querySelectorAll("a")];
68+
// const de = links
69+
// .map(link => link.textContent)
70+
// .filter(streetName => streetName.includes('de'));
5571

5672

5773
// 7. sort Exercise
5874
// Sort the people alphabetically by last name
75+
// const sortName = people.sort((a,b) => {
76+
// const [aLast, aFirst] = a.split(', ');
77+
// const [bLast, bFirst] = b.split(', ');
78+
// return aLast > bLast ? 1 : -1;
79+
// });
80+
// console.table(sortName);
5981

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

86+
const transport = data.reduce((obj, item) => {
87+
if(!obj[item]){
88+
obj[item] = 0;
89+
}
90+
obj[item]++;
91+
return obj;
92+
}, {});
93+
console.log(transport);
94+
6495
</script>
6596
</body>
6697
</html>

04 - Array Cardio Day 1/index.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<script>
10+
// const inventors = [
11+
// { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },
12+
// { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },
13+
// { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },
14+
// { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 },
15+
// { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 },
16+
// { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 },
17+
// { first: 'Max', last: 'Planck', year: 1858, passed: 1947 },
18+
// { first: 'Katherine', last: 'Blodgett', year: 1898, passed: 1979 },
19+
// { first: 'Ada', last: 'Lovelace', year: 1815, passed: 1852 },
20+
// { first: 'Sarah E.', last: 'Goode', year: 1855, passed: 1905 },
21+
// { first: 'Lise', last: 'Meitner', year: 1878, passed: 1968 },
22+
// { first: 'Hanna', last: 'Hammarström', year: 1829, passed: 1909 }
23+
// ];
24+
25+
// console.log(inventors[0].first, inventors[0].last);
26+
27+
const arr = ['Ifham, Hashir', 'Lionel, Messi'];
28+
const [aFirst, aLast] = arr[0].split(', ');
29+
const [bFirst, bLast] = arr[0].split(', ');
30+
const sorted = arr.sort((aLast,bLast) => aLast > bLast ? -1 : 1);
31+
console.log(sorted);
32+
33+
</script>
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)