Skip to content

Instantly share code, notes, and snippets.

@dirkdunn
Last active March 7, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkdunn/092963d207c26c6d358779031cbc4b6d to your computer and use it in GitHub Desktop.
Save dirkdunn/092963d207c26c6d358779031cbc4b6d to your computer and use it in GitHub Desktop.

Array Zipper

Using two existing arrays, create a new array that contains all of the items from array1 and array2 in a "zipped" like fashion.

So for example

// Array 1
[1,2,3,4,5,6,7]

// Array 2
[7,6,5,4,3,2,1]

// Array3 We create
[ 1, 7, 2, 6, 3, 5, 4, 4, 5, 3, 6, 3, 7, 2, 1 ]

BONUS Can you make it so it works for two arrays of different sizes without "undefined" showing up in the new array?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment