Last active
December 27, 2015 17:29
-
-
Save animatedlew/7362378 to your computer and use it in GitHub Desktop.
In this exercise, I transform given data into a list of objects that have 'first' and 'last' labels as keys.
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
var data = { | |
first: ["Alvaro", "Lewis", "Craig"], | |
last: ["Carrasco", "Moronta", "Pottinger"] | |
}, result = []; | |
var combineNames = function() { | |
return _.zip(_.values(data)[0], _.values(data)[1]); | |
}; | |
var assignKeys = function(name) { | |
return _.object(_.keys(data), name); | |
}; | |
result = _.map(combineNames(), function(name) { | |
return assignKeys(name); | |
}); | |
// [{first: "Alvaro", last: "Carrasco"}, {first: "Lewis", last: "Moronta"}, ...] | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment