Skip to content

Instantly share code, notes, and snippets.

@thmain
Created December 25, 2022 05:30
Show Gist options
  • Save thmain/61ac77c7757d3114cde8d4b87d527134 to your computer and use it in GitHub Desktop.
Save thmain/61ac77c7757d3114cde8d4b87d527134 to your computer and use it in GitHub Desktop.
'use strict';
Array.prototype.zip = function(left, right, combinerFunction) {
let results, length;
length = Math.min(left.length, right.length);
results = [];
for (let i = 0; i < length; i++) {
results.push(combinerFunction(left[i], right[i]));
}
return results;
}
console.log([].zip([1, 2], [1, 2, 3], function(l, r) {
return l + r;
})); // [2, 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment