Skip to content

Commit 630ff54

Browse files
author
laryl.li
committed
Solved wesbos#7 Sort the people alphabetically by last name
1 parent 1f50dce commit 630ff54

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@
7575

7676
// 7. sort Exercise
7777
// Sort the people alphabetically by last name
78+
const sortedlastname = people.sort(sortbylastname);
79+
80+
function sortbylastname(a,b){
81+
return (getlastname(a)>getlastname(b));
82+
}
83+
84+
function getlastname(namevalue){
85+
fullname = namevalue.split(", ");
86+
return fullname[0];
87+
}
88+
89+
console.log(sortedlastname);
7890

7991
// 8. Reduce Exercise
8092
// Sum up the instances of each of these

0 commit comments

Comments
 (0)