Created
December 25, 2022 05:30
-
-
Save thmain/185014991827070f9a43c65589d752da to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
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 | |
}], | |
counter, | |
videoIdAndBookmarkIdPairs = []; | |
for (counter = 0; counter < Math.min(videos.length, bookmarks.length); counter++) { | |
videoIdAndBookmarkIdPairs.push({ | |
videoId: videos[counter].id, | |
bookmarkId: bookmarks[counter].id | |
}); | |
} | |
return videoIdAndBookmarkIdPairs; | |
} | |
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