Skip to content
Prev Previous commit
Next Next commit
Solved wesbos#7 Sort the people alphabetically by last name
  • Loading branch information
laryl.li committed Feb 9, 2020
commit 630ff5404a500707a740a281c6ab48f6bbe1c2ee
12 changes: 12 additions & 0 deletions 04 - Array Cardio Day 1/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@

// 7. sort Exercise
// Sort the people alphabetically by last name
const sortedlastname = people.sort(sortbylastname);

function sortbylastname(a,b){
return (getlastname(a)>getlastname(b));
}

function getlastname(namevalue){
fullname = namevalue.split(", ");
return fullname[0];
}

console.log(sortedlastname);

// 8. Reduce Exercise
// Sum up the instances of each of these
Expand Down