Last active
December 17, 2018 15:04
-
-
Save productioncoder/7810d72555783300aa12c79bf44727d3 to your computer and use it in GitHub Desktop.
Youtube videos reducer: group videos by id and category
This file contains 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
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