Skip to content

Commit 1a9b6c8

Browse files
author
laryl.li
committed
Solved wesbos#3 Array.prototype.sort()
1 parent e51a0da commit 1a9b6c8

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
// Array.prototype.map()
3939
// 2. Give us an array of the inventors first and last names
40-
const finalnamestring = inventors.map(firstandlastname)
40+
const finalnamestring = inventors.map(firstandlastname);
4141
function firstandlastname (x){
4242
const space = ' '
4343
const namestring = x.first + space + x.last;
@@ -48,6 +48,11 @@
4848

4949
// Array.prototype.sort()
5050
// 3. Sort the inventors by birthdate, oldest to youngest
51+
const sort = inventors.sort(oldesttoyoungest);
52+
function oldesttoyoungest(a,b){
53+
return a.year-b.year;
54+
}
55+
console.log(sort);
5156

5257
// Array.prototype.reduce()
5358
// 4. How many years did all the inventors live all together?

0 commit comments

Comments
 (0)