Skip to content

Commit

Permalink
Fix challenge ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Jul 29, 2016
1 parent cc8b608 commit ad93e49
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/services/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ function cachedMap(Block) {
}, {})
.map(map => normalize(map, mapSchema))
.map(map => {
// make sure challenges are in the right order
map.entities.block = Object.keys(map.entities.block)
// turn map into array
.map(key => map.entities.block[key])
// perform re-order
.map(block => {
block.challenges = block.challenges.reduce((accu, dashedName) => {
const index = map.entities.challenge[dashedName].suborder;
accu[index - 1] = dashedName;
return accu;
}, []);
return block;
})
// turn back into map
.reduce((blockMap, block) => {
blockMap[block.dashedName] = block;
return blockMap;
}, {});
return map;
})
.map(map => {
// re-order superBlocks result
const result = Object.keys(map.result).reduce((result, supName) => {
const index = map.entities.superBlock[supName].order;
result[index] = supName;
Expand Down

0 comments on commit ad93e49

Please sign in to comment.