Skip to content

Instantly share code, notes, and snippets.

@bahmutov
Created July 31, 2014 03:27
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 bahmutov/17c31f834509c0f0fd12 to your computer and use it in GitHub Desktop.
Save bahmutov/17c31f834509c0f0fd12 to your computer and use it in GitHub Desktop.
Unique items from Array by calling a method
var _ = require('lodash');
var fp = require('functional-pipeline');
var items = [{
toString: function () {
return 'foo';
}
}, {
toString: function () {
return 'bar';
}
}, {
toString: function () {
return 'foo';
}
}];
var result = _.unique(items, fp('toString'));
// same as
result = _.unique(items, function (item) {
return item.toString();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment