Rewrite challenge controller to use dashed names, update index.js to include new utility function getDashedNames

This commit is contained in:
terakilobyte
2015-06-15 18:50:18 -04:00
parent a334b9870c
commit c136895064
2 changed files with 31 additions and 27 deletions

View File

@@ -16,7 +16,8 @@ var path = require('path'),
*/
var allFieldGuideIds, allFieldGuideNames, allNonprofitNames,
challengeMap, challengeMapForDisplay, challengeMapWithIds,
challengeMapWithNames, allChallengeIds, allChallenges;
challengeMapWithNames, allChallengeIds, allChallenges,
challengeMapWithDashedNames;
/**
* GET /
@@ -98,17 +99,6 @@ module.exports = {
return allChallengeIds;
},
allChallenges: function () {
if (!allChallenges) {
allChallenges = [];
Object.keys(this.getChallengeMapWithNames()).forEach(function (key) {
allChallenges.push(challengeMap[key].challenges);
});
allChallenges = R.flatten(allChallenges);
}
return allChallenges;
},
getChallengeMapWithNames: function () {
if (!challengeMapWithNames) {
challengeMapWithNames = {};
@@ -123,6 +113,20 @@ module.exports = {
return challengeMapWithNames;
},
getChallengeMapWithDashedNames: function() {
if (!challengeMapWithDashedNames) {
challengeMapWithDashedNames = {};
Object.keys(challengeMap).
forEach(function (key) {
var onlyNames = challengeMap[key].challenges.map(function (elem) {
return elem.dashedName;
});
challengeMapWithDashedNames[key] = onlyNames;
});
}
return challengeMapWithDashedNames;
},
randomPhrase: function () {
return resources.phrases[