Created
February 24, 2017 19:40
-
-
Save chasen-bettinger/950f6551cbb16d95da52465fed83057a to your computer and use it in GitHub Desktop.
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
var moonWalkers = [ | |
"Neil Armstrong", | |
"Buzz Aldrin", | |
"Pete Conrad", | |
"Alan Bean", | |
"Alan Shepard", | |
"Edgar Mitchell", | |
"David Scott", | |
"James Irwin", | |
"John Young", | |
"Charles Duke", | |
"Eugene Cernan", | |
"Harrison Schmitt" | |
]; | |
function alphabetizer(names) { | |
var newNames = []; | |
for(var i = 0; i < names.length; i++) { | |
var newName = names[i].split(' '); | |
var lastName = newName[1]; | |
var firstName = newName[0]; | |
newNames.push(lastName + ", " + firstName); | |
} | |
return newNames.sort(); | |
} | |
// Try logging your results to test your code! | |
console.log(alphabetizer(moonWalkers)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment