Created
July 31, 2014 03:27
-
-
Save bahmutov/17c31f834509c0f0fd12 to your computer and use it in GitHub Desktop.
Unique items from Array by calling a method
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
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