hankknight
asked on
JavaScript: Order Array by Last Name
How can I order this list by last name?
This does NOT work:
This does NOT work:
var str = 'X. Michael Goo,Suzy M. Kat,Sal M. Haircut,Scott N. Yuu,Larry B. Huff,Geof L. Mack,David A. Xaa,Brian C. Fuu';
var people = str.split(',');
people = people.sort(function(a,b){return a<b;});
alert(people.join('\n'))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
return last_a<last_b?-1:1;
so that the 1 and -1 are swapped:
return last_a<last_b?1:-1;