2018-05-15 14:56:26 +01:00
|
|
|
import { find } from 'lodash';
|
|
|
|
|
2018-02-16 23:18:53 +00:00
|
|
|
export const jsProjectSuperBlock = 'javascript-algorithms-and-data-structures';
|
|
|
|
|
2018-05-15 14:56:26 +01:00
|
|
|
export function buildUserProjectsMap(projectBlock, completedChallenges) {
|
2018-02-16 23:18:53 +00:00
|
|
|
const {
|
|
|
|
challenges,
|
|
|
|
superBlock
|
|
|
|
} = projectBlock;
|
|
|
|
return {
|
|
|
|
[superBlock]: challenges.reduce((solutions, current) => {
|
2018-03-05 14:15:30 +00:00
|
|
|
const { id } = current;
|
2018-05-15 14:56:26 +01:00
|
|
|
const completed = find(
|
|
|
|
completedChallenges,
|
|
|
|
({ id: completedId }) => completedId === id
|
|
|
|
);
|
2018-02-16 23:18:53 +00:00
|
|
|
let solution = '';
|
|
|
|
if (superBlock === jsProjectSuperBlock) {
|
|
|
|
solution = {};
|
|
|
|
}
|
|
|
|
if (completed) {
|
|
|
|
solution = 'solution' in completed ?
|
|
|
|
completed.solution :
|
2018-06-12 16:50:35 +01:00
|
|
|
completed.files || '';
|
2018-02-16 23:18:53 +00:00
|
|
|
}
|
|
|
|
return {
|
|
|
|
...solutions,
|
2018-03-05 14:15:30 +00:00
|
|
|
[current.title]: solution
|
2018-02-16 23:18:53 +00:00
|
|
|
};
|
|
|
|
}, {})
|
|
|
|
};
|
|
|
|
}
|