Last active
June 7, 2018 04:05
-
-
Save Daniel-Hug/53be05c383eacb1ff8f5fd70e7ce788b 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 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