Skip to content

Instantly share code, notes, and snippets.

@rexxars
Created August 15, 2014 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rexxars/8ce51e1b2dec75275919 to your computer and use it in GitHub Desktop.
Save rexxars/8ce51e1b2dec75275919 to your computer and use it in GitHub Desktop.
SortBy with deep object access
'use strict';
function deep(obj, prop) {
var segs = prop.split('.');
while (segs.length) {
obj = obj[segs.shift()];
}
return obj;
}
module.exports = function(prop) {
return function(item) {
return deep(item, prop);
};
};
// Usage:
var deep = require('deep'); // `deep` being the above
_.sortBy(arr, deep('some.nested.key'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment