Created
January 10, 2014 07:19
-
-
Save spencewood/8348127 to your computer and use it in GitHub Desktop.
Underscore nested pluck mixin. Takes an array as the first argument and any number of keys as additional arguments. E.g.: _.nestedPluck(arr, 'person', 'name', 'first');
This file contains 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
_.mixin({ | |
nestedPluck: function nestedPluck(arr) { | |
var plucks = _.rest(arguments); | |
if (plucks.length > 0) { | |
var a = _.flatten(_.pluck(arr, plucks.shift()), true); | |
return nestedPluck.apply(null, [a].concat(plucks)); | |
} | |
return arr; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment