Skip to content

Instantly share code, notes, and snippets.

@celsowhite
Created July 10, 2018 22:36
Show Gist options
  • Save celsowhite/b752569fa2b7c30cc1c5bd12feb2f2a7 to your computer and use it in GitHub Desktop.
Save celsowhite/b752569fa2b7c30cc1c5bd12feb2f2a7 to your computer and use it in GitHub Desktop.
Plain List Sort
// Sort a plain list of names alphabetically.
const people = `
Mike Dobbs
Peace Walker
Adam Vinson
`;
// Convert the list to an array. Splitting on the new line.
const peopleArray = people.split('\n');
// Sort alphabetically
peopleArray.sort();
// Re-join the array into a string with new lines
const peopleOrganized = peopleArray.join('\n');
console.log(peopleOrganized);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment