forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
61 lines (59 loc) · 1.46 KB
/
Copy pathmap.js
File metadata and controls
61 lines (59 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import emptyProtector from './empty-protector';
export function checkMapData({
entities: { challenge, block, superBlock },
result: { superBlocks }
}) {
if (
!challenge ||
!block ||
!superBlock ||
!superBlocks ||
!superBlocks.length
) {
throw new Error('entities not found, db may not be properly seeded');
}
}
// getFirstChallenge(
// map: {
// entities: { challenge: Object, block: Object, superBlock: Object },
// result: [...superBlockDashedName: String]
// }
// ) => Challenge|Void
export function getFirstChallenge({
entities: { superBlock, block, challenge },
result: { superBlocks }
}) {
return challenge[
emptyProtector(block[emptyProtector(superBlock[superBlocks[0]]).blocks[0]])
.challenges[0]
];
}
// let challengeDashedName: String;
// createNameIdMap({
// challenge: {
// [...challengeDashedName ]: Challenge
// }) => {
// challengeIdToName: {
// [ ...challengeId ]: challengeDashedName
// }
// };
export function createNameIdMap({ challenge }) {
return {
challengeIdToName: Object.keys(challenge).reduce((map, challengeName) => {
map[challenge[challengeName].id] = challenge[challengeName].dashedName;
return map;
}, {})
};
}
// addNameIdMap(
// map: { entities; Object, ...rest }
// ) => { ...rest, entities: Object };
export function addNameIdMap({ entities, ...rest }) {
return {
...rest,
entities: {
...entities,
...createNameIdMap(entities)
}
};
}