Last active
December 2, 2016 13:40
-
-
Save jineeshjohn/9f72286bec4ac76316ade73a2541d5a5 to your computer and use it in GitHub Desktop.
Single level of abstraction - SLA
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
var responseJson = [ | |
{type: 'input', id: 'key1', styles:{display:'block', color: 'red'}, someprop:'abc', someotherprop:'bcd'}, | |
{type: 'radio', id: 'key2', styles:{display:'inline', color: 'blue'}, someprop:'xyz', someotherprop:'z'} | |
] | |
var parseResponse = function(response) { | |
var result = []; | |
for (var i=0; i<response.length; i++) { | |
var resultObj = { | |
type: response[i].type, | |
id: response[i].id, | |
styles: response[i].styles, | |
someprop: response[i].someprop | |
} | |
result.push(resultObj); | |
} | |
return result; | |
} | |
var parseResponse2 = function(response) { | |
return _.map(response, function(item){ // Iteration | |
return _.pick(item, 'type', 'id', 'styles', 'someprop'); // picking the relevent properties | |
}); | |
} | |
var result = parseResponse(responseJson); | |
var result = parseResponse2(responseJson); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment