-
-
Save gregorynicholas/3b3fc5ea9c2f47fa458b31c877547118 to your computer and use it in GitHub Desktop.
Zip arrays into one | Example with two arrays: value 0 from a, value 0 from b, value 1 from a, etc.
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
// Zip arrays into one | |
// Example with two arrays: value 0 from a, value 0 from b, value 1 from a, etc. | |
function zipArrays() { | |
var zipped = []; | |
var arrays = [].slice.call(arguments); | |
for (var valueI = 0; arrays.length > 0; valueI++) { | |
for (var arrayI = 0; arrayI < arrays.length; arrayI++) { | |
if (arrays[arrayI].length - 1 < valueI) { | |
arrays.splice(arrayI, 1); | |
continue; | |
} | |
zipped.push(arrays[arrayI][valueI]); | |
} | |
} | |
return zipped; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment