Skip to content

Instantly share code, notes, and snippets.

@kijanawoodard
Created January 21, 2014 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kijanawoodard/8545863 to your computer and use it in GitHub Desktop.
Save kijanawoodard/8545863 to your computer and use it in GitHub Desktop.
Utilities = {
asArray: function (obj) {
var result = [];
for (var key in obj) {
var node = { key: key, value: obj[key] };
result.push(node);
}
return result;
},
asObject: function (array, keyFunc) {
keyFunc = keyFunc || function (item) {
return item.id;
};
var result = {};
_.each(array, function (item) {
result[keyFunc(item)] = item;
});
return result;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment