A team directory shows people sorted by last name, and by first name when last names match. contacts holds objects { first, last }. Every name is one capital letter followed by lowercase letters, so plain character-code comparison gives alphabetical order.
Write sortContacts(contacts) that returns the full names as strings "First Last", in that order. People with the same first and last name keep their original order.
Input: contacts = [{"first":"Grace","last":"Hopper"},{"first":"Ada","last":"Lovelace"},{"first":"Alan","last":"Hopper"}] Output: ["Alan Hopper","Grace Hopper","Ada Lovelace"]
Both Hoppers come before Lovelace; between them, Alan comes before Grace.
Input: contacts = [{"first":"Li","last":"Wei"},{"first":"Li","last":"Ng"}] Output: ["Li Ng","Li Wei"]
Last names decide first.
0 <= contacts.length <= 10000[A-Z][a-z]*.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #219 Contacts by Last Name. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.