Created
July 21, 2016 09:53
-
-
Save hieptuanle/439f0d4a9adb403c4cc25593e56e7053 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const debug = _.curry((tag, x) => { | |
console.log(tag, x) | |
return x | |
}) | |
$http.get('/quizzes/' + $stateParams.quizId + '/do') | |
.success(function (response) { | |
$scope.paper = response.paper | |
const questions = response.paper.questions | |
// getAnswerse :: Question -> Answer[] | |
const getAnswers = _.property('question.answers') | |
// getRightAnswer :: Answer[] -> Answer | |
const getRightAnswer = answers => { return _.find(answers, {isKey: true}) } | |
// getAnswerContent :: Answer[] -> String | |
const getAnswerContent = _.property('content') | |
// getContentFromQuestion :: Question -> String | |
const getContentFromQuestion = _.compose(debug('getRightAnswer'), getAnswerContent, debug('getRightAnswer'), getRightAnswer,debug('getAnswers'), getAnswers) | |
// setRightAnswerContent :: Question -> QuestionWithRightAnswer | |
const getQuestionWithRightAnswer = _.curry((question, content) => _.assign({}, question, {answers: content})) | |
$scope.paper.questions = questions.map(question => getQuestionWithRightAnswer(question, getContentFromQuestion(question))) | |
console.log('$scope.paper.questions', $scope.paper.questions) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment