-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optional parameter for predicate on _.unique #2368
Conversation
this allows for using custom matcher function for comparison defaults to _.isEqual jashkenas#2311
I think this would have a better chance of landing without bundling it with |
this is an additional last predicate parameter rather than defining new methods for using equality comparison other than ===
Ive updated this to use a predicate parameter #2311 _.uniq = _.unique = function(array, isSorted, iteratee, context, predicate) {
//... |
if (!_.isBoolean(isSorted)) { | ||
context = iteratee; | ||
iteratee = isSorted; | ||
isSorted = false; | ||
predicate = _.isNull(predicate) ? context : predicate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
predicate == null && _.isFunction(context) ? ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that would be better to ensure that context is a function before assigning it to predicate. thanks.
using optimizeCb for binding making sure that context is a function before assigning to predicate in overloading of unique
made the suggested changes, thanks @megawac |
this allows for using custom matcher function for comparison
defaults to
_.isEqual
for comparison #2311added a
_.uniqueWith
function as discussed, also added_.includeWith
as a method to detect if an Array or Collection has an item passing a method. This will be useful if we implement the other methods discussed in the thread as well.