Skip to content

Instantly share code, notes, and snippets.

@stepheneyer
Created May 1, 2015 16:21
Show Gist options
  • Save stepheneyer/bc9397fd6c1ef49dcf9a to your computer and use it in GitHub Desktop.
Save stepheneyer/bc9397fd6c1ef49dcf9a to your computer and use it in GitHub Desktop.
Combine two arrays into one, then sort
//Assign a new variable for each array
var myFriends = ["Rickon", "Meera", "Hodor", "Jojen", "Osha", "Rickard", "Maester", "Rodrik", "Jory", "Septa", "Jon"]
var yourFriends = ["Bilbo", "Boromir", "Elrond", "Faramir", "Frodo", "Gandalf", "Legolas", "Pippin"]
//Combine the two arrays using the .concat() method
var combinedFriends = myFriends.concat(yourFriends);
combinedFriends.sort();
//=> [ 'Bilbo',
// 'Boromir',
// 'Elrond',
// 'Faramir',
// 'Frodo',
// 'Gandalf',
// 'Hodor',
// 'Jojen',
// 'Jon',
// 'Jory',
// 'Legolas',
// 'Maester',
// 'Meera',
// 'Osha',
// 'Pippin',
// 'Rickard',
// 'Rickon',
// 'Rodrik',
// 'Septa' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment