Last active
January 23, 2017 19:24
-
-
Save pedrojimenezp/8ac800da27a35eb00f1af2c46141d7d9 to your computer and use it in GitHub Desktop.
Function that combine many arrays into one array
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
function combine(mapFunc) { | |
return function() { | |
const args = Array.prototype.slice.call(arguments); | |
const lengths = args.map(arg => arg.length) | |
const minLength = Math.min.apply(this, lengths) | |
const combined = [] | |
for (let i = 0; i < minLength; i++) { | |
combined.push(mapFunc(args.map(arg => arg[i]))) | |
} | |
return combined | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment