Skip to content

Instantly share code, notes, and snippets.

@chrdek
Created November 25, 2018 22:32
Show Gist options
  • Save chrdek/16ec75a7c3803038a7aaa13907f828a5 to your computer and use it in GitHub Desktop.
Save chrdek/16ec75a7c3803038a7aaa13907f828a5 to your computer and use it in GitHub Desktop.
Transform onedim arrays into twodim..
var a = [0,1,2,3,4],
b = [5,6,7,8,9];
Array.prototype.zip = function (arr) {
return this.map(function (e, i) {
return [e, arr[i]];
})
};
//Usage: a.zip(b) = [[0,5], [1,6], [2,7], [3,8], [4,9]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment