WikiEducationFoundation/WikiEduDashboard

View on GitHub
app/assets/javascripts/components/students/utils/groupArticlesCoursesByUserId.js

Summary

Maintainability
A
0 mins
Test Coverage
F
50%
// This function organizes the articles data to be sorted by userId first,
// followed by the articleId.
export default (articles) => {
  return articles.reduce((acc, article) => {
    article.user_ids.forEach((id) => {
      if (acc[id]) {
        acc[id].push(article);
      } else {
        acc[id] = [article];
      }
    });
    return acc;
  }, {});
};