Skip to content

Commit ebebae3

Browse files
committed
.sort() Method
1 parent 5c60924 commit ebebae3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,24 @@
4545

4646
// Array.prototype.map()
4747
// 2. Give us an array of the inventors' first and last names
48+
49+
//this is the function to run in the map method
50+
inventors.map(
51+
function joinNames(currentItem, indexOfItem){
52+
let fullName = [currentItem.first, currentItem.last].join(" ");
53+
console.log(fullName)
54+
});
55+
4856

4957
// Array.prototype.sort()
5058
// 3. Sort the inventors by birthdate, oldest to youngest
59+
// compare function will be needed
60+
let sortbyYears = inventors.sort(function(firstPerson, secondPerson){
61+
if (firstPerson.year > secondPerson.year){console.log (firstPerson, secondPerson); return 1}else{return -1}
62+
63+
})
5164

65+
console.log(sortbyYears);
5266
// Array.prototype.reduce()
5367
// 4. How many years did all the inventors live?
5468

0 commit comments

Comments
 (0)