Skip to content

Instantly share code, notes, and snippets.

@thmain
Created December 25, 2022 05:30
Show Gist options
  • Save thmain/bf09aed633e61109cac554bb20989707 to your computer and use it in GitHub Desktop.
Save thmain/bf09aed633e61109cac554bb20989707 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;
}
function zip() {
var videos = [{
"id": 70111470,
"title": "Die Hard",
"rating": 4.0
}, {
"id": 654356453,
"title": "Bad Boys",
"rating": 5.0
}, {
"id": 65432445,
"title": "The Chamber",
"rating": 4.0
}, {
"id": 675465,
"title": "Fracture",
"rating": 5.0
}],
bookmarks = [{
id: 470,
time: 23432
}, {
id: 453,
time: 234324
}, {
id: 445,
time: 987834
}];
return Array.prototype.zip(videos, bookmarks, function(l, r) {
return {
videoId: l.id,
bookmarkId: r.id
};
});
}
console.log(zip());
/*
[
{bookmarkId: 470, videoId: 70111470},
{bookmarkId: 453, videoId: 654356453},
{bookmarkId: 445, videoId: 65432445}
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment