Skip to content

Instantly share code, notes, and snippets.

@michaeldjeffrey
Created January 20, 2016 19:07
Show Gist options
  • Save michaeldjeffrey/8b30880b6e041b2da677 to your computer and use it in GitHub Desktop.
Save michaeldjeffrey/8b30880b6e041b2da677 to your computer and use it in GitHub Desktop.
//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