Created
May 1, 2015 16:21
-
-
Save stepheneyer/bc9397fd6c1ef49dcf9a to your computer and use it in GitHub Desktop.
Combine two arrays into one, then sort
This file contains 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
//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