Created
July 10, 2018 22:36
-
-
Save celsowhite/b752569fa2b7c30cc1c5bd12feb2f2a7 to your computer and use it in GitHub Desktop.
Plain List Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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