You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have something working for this, is there any interest in adding functionality like this to the repo? I can submit a PR if needed, just wanted to gauge interest before I start adding tests and getting my code styled correctly.
Just as a followup here, here is a more readable and more underscore-y method.
function zipObj(obj) {
// First get keys from object.
var keys = _.keys(obj);
// For each key, grab the data
var propertyArray = _.map(keys, function(k, i) { return obj[k] || undefined; });
// "Shift" propertyArray around, so we can make into array of objects
var zippedArray = _.zip.apply(_, propertyArray);
// Set up function that will take an array,
// Then use the keys variable to re-create.
var createObject = function(d) {
var rObj = {};
_.each(keys, function(k, i) { rObj[k] = d[i]; });
return rObj;
};
// For each item in zipped array, return an object
return _.map(zippedArray, createObject);
}
Feel free to let me know of any issues you might have with a PR for this.
I didn't find any other requests similar to this, so forgive me if there has been one already.
Underscore supplies a method called
zip
, which is great. What I'm wanting is the ability to zip objects by their keys.I have something working for this, is there any interest in adding functionality like this to the repo? I can submit a PR if needed, just wanted to gauge interest before I start adding tests and getting my code styled correctly.
My first pass at implementation:
The text was updated successfully, but these errors were encountered: