Files
freeCodeCamp/common/app/routes/Settings/utils/buildUserProjectsMap.js
Stuart Taylor f916204ba5 Chore: Update User model (#17171)
* fix(logs): Remove console.log's

* chore(challengeMap): challengeMap -> completedChallenges

* chore(userModel): Update user model

* feat(userIDs): Add user ident fields

* chore(github): Remove more refs to github data
2018-05-15 19:26:26 +05:30

33 lines
807 B
JavaScript

import { find } from 'lodash';
export const jsProjectSuperBlock = 'javascript-algorithms-and-data-structures';
export function buildUserProjectsMap(projectBlock, completedChallenges) {
const {
challenges,
superBlock
} = projectBlock;
return {
[superBlock]: challenges.reduce((solutions, current) => {
const { id } = current;
const completed = find(
completedChallenges,
({ id: completedId }) => completedId === id
);
let solution = '';
if (superBlock === jsProjectSuperBlock) {
solution = {};
}
if (completed) {
solution = 'solution' in completed ?
completed.solution :
completed.files;
}
return {
...solutions,
[current.title]: solution
};
}, {})
};
}