Created
February 5, 2019 19:58
-
-
Save isaac-martin/21b91d98e544d9791c32a40fce9f30f0 to your computer and use it in GitHub Desktop.
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
groupData = posts => { | |
const array = Object.values(posts); | |
const res = array.reduce((acc, curr) => { | |
if (!acc[curr.data.subreddit]) { | |
acc[curr.data.subreddit] = []; | |
} | |
// If this subreddit wasn't previously stored create an empty array | |
acc[curr.data.subreddit].push(curr); // Add the post to group | |
return acc; | |
}, {}); | |
return Object.values(res); // convert to array and return | |
}; | |
// Group by key in data | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment