Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active December 27, 2015 17:29
Show Gist options
  • Save animatedlew/7362378 to your computer and use it in GitHub Desktop.
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.
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