Skip to content

Instantly share code, notes, and snippets.

@productioncoder productioncoder/videos.js
Last active Dec 17, 2018

Embed
What would you like to do?
Youtube videos reducer: group videos by id and category
function groupVideosByIdAndCategory(response) {
const videos = response.items;
const byId = {};
const byCategory = {
totalResults: response.pageInfo.totalResults,
nextPageToken: response.nextPageToken,
items: [],
};
videos.forEach((video) => {
byId[video.id] = video;
const items = byCategory.items;
if(items && items) {
items.push(video.id);
} else {
byCategory.items = [video.id];
}
});
return {byId, byCategory};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.