Skip to content

Commit ff9ef1e

Browse files
author
QbanCowboy
committed
In-prog: working through the array exercises
1 parent ed2b900 commit ff9ef1e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
4141
return person.first + " " + person.last;
4242
});
4343

44-
console.log(firstAndLast);
45-
46-
4744
// Array.prototype.sort()
4845
// 3. Sort the inventors by birthdate, oldest to youngest
49-
inventors.sort(function(a, b){
50-
a.year > b.year;
51-
});
52-
console.log (inventors);
46+
inventors.sort(function(a, b){return a.year - b.year;});
47+
5348

5449

5550
// Array.prototype.reduce()
5651
// 4. How many years did all the inventors live?
52+
const totalYears = inventors.reduce(function(total, person){
53+
console.log (person.passed-person.year);
54+
return total+(person.passed-person.year);
55+
});
56+
console.log (totalYears);
5757

5858
// 5. Sort the inventors by years lived
5959

0 commit comments

Comments
 (0)