Created
January 20, 2016 19:07
-
-
Save michaeldjeffrey/8b30880b6e041b2da677 to your computer and use it in GitHub Desktop.
This file contains 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
//assuming angulars $http | |
function fetchQuestions(url){ | |
return $http.get(url) | |
.then(response => response.data) | |
.then(extractObject('answer', receiveAnswers)) | |
.then(receiveQuestions); | |
} | |
function extractObject(key, fc){ | |
return function(items){ | |
fn(items.filter(item => !!item[key]).map(item => item[key])); | |
return items; | |
} | |
} | |
function receiveAnswers(answers){ | |
// store answers | |
} | |
function receiveQuestions(questions){ | |
// store questions | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment