Skip to content

Commit 2534c50

Browse files
committed
solved wesbos#4
1 parent 2986d55 commit 2534c50

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
console.log(fullName);
4747
// Array.prototype.sort()
4848
// 3. Sort the inventors by birthdate, oldest to youngest
49-
const ageSort = inventors.sort(function sorting(a,b){
49+
/*const ageSort = inventors.sort(function sorting(a,b){
5050
if (a.year > b.year){
5151
return 1
5252
} else if (a.year == b.year){
@@ -55,12 +55,19 @@
5555
return -1
5656
};
5757
58-
});
58+
});*/
59+
const ageSort = inventors.sort((a,b) => a.year > b.year ? 1 : -1);
5960
console.table(ageSort);
6061
// Array.prototype.reduce()
6162
// 4. How many years did all the inventors live all together?
63+
const totalYears = inventors.reduce((total, inventor) => {
64+
return total+(inventor.passed-inventor.year);
65+
}, 0);
66+
console.log(totalYears);
6267

6368
// 5. Sort the inventors by years lived
69+
const yearsLived = inventors.sort((a,b) => (a.passed-a.year) > (b.passed-b.year) ? 1 : -1);
70+
console.table(yearsLived);
6471

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

0 commit comments

Comments
 (0)