Skip to content

Instantly share code, notes, and snippets.

@pedrojimenezp
Last active January 23, 2017 19:24
Show Gist options
  • Save pedrojimenezp/8ac800da27a35eb00f1af2c46141d7d9 to your computer and use it in GitHub Desktop.
Save pedrojimenezp/8ac800da27a35eb00f1af2c46141d7d9 to your computer and use it in GitHub Desktop.
Function that combine many arrays into one array
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