Skip to content

Commit 73ca06d

Browse files
Update array cardio day 1 project
1 parent ced231a commit 73ca06d

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

04 - Array Cardio Day 1/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- <div align="center">
22
3-
![Array cardio day 1]()
3+
![Console screenshot]()
44
55
</div> -->

04 - Array Cardio Day 1/js/array.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,42 +62,39 @@ const people = [
6262

6363
// Array.prototype.filter()
6464
// 1. Filter the list of inventors for those who were born in the 1500's
65-
// const a = inventors.filter(
66-
// (inventor) => inventor.year < 1600 && 1500 <= inventor.year
67-
// );
68-
// console.table(a);
65+
const a = inventors.filter(
66+
(inventor) => inventor.year < 1600 && 1500 <= inventor.year
67+
);
68+
console.table(a);
6969

7070
// Array.prototype.map()
7171
// 2. Give us an array of the inventors first and last names
72-
// const b = inventors.map((inventor) =>
73-
// console.log(`${inventor.first} ${inventor.last}`)
74-
// );
72+
const b = inventors.map((inventor) => `${inventor.first} ${inventor.last}`);
73+
console.log(b);
7574

7675
// Array.prototype.sort()
7776
// 3. Sort the inventors by birthdate, oldest to youngest
78-
// const c = inventors.sort((i, l) => i.year - l.year);
79-
// console.table(c);
77+
const c = inventors.sort((i, l) => i.year - l.year);
78+
console.table(c);
8079

8180
// Array.prototype.reduce()
8281
// 4. How many years did all the inventors live all together?
83-
// let d = inventors.reduce(function (acc, inventor) {
84-
// return acc + (inventor.passed - inventor.year);
85-
// }, 0);
86-
// console.log(d);
82+
const d = inventors.reduce(
83+
(acc, inventor) => acc + (inventor.passed - inventor.year),
84+
0
85+
);
86+
console.log(d);
8787

8888
// 5. Sort the inventors by years lived
89-
// let f = inventors.sort((a, b) => a.passed - b.year);
90-
// console.log(f);
89+
let f = inventors.sort((a, b) => b.passed - b.year - (a.passed - a.year));
90+
console.table(f);
9191

9292
// 6. Create a list of Boulevards in Paris that contain 'de' anywhere in the name
9393
// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
9494

9595
// 7. Sort exercise
9696
// Sort the people alphabetically by last name
97-
// for (let i = 0; i < people.length; i++) {
98-
// let lastName = people[i].split(" ")[1];
99-
// console.log();
100-
// }
97+
console.log(people.sort());
10198

10299
// 8. Reduce exercise
103100
// Sum up the instances of each of these

0 commit comments

Comments
 (0)