Skip to content

Instantly share code, notes, and snippets.

@chasen-bettinger
Created February 24, 2017 19:40
Show Gist options
  • Save chasen-bettinger/950f6551cbb16d95da52465fed83057a to your computer and use it in GitHub Desktop.
Save chasen-bettinger/950f6551cbb16d95da52465fed83057a to your computer and use it in GitHub Desktop.
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