-
Notifications
You must be signed in to change notification settings - Fork 189
Rename scan to leastIndex; add least. #108
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
Conversation
Can we make least accept an accessor as well as comparator ?
d3.bisector accepts both https://github.com/d3/d3-array#bisector, using ascendingComparator — not sure if this is generalizable. |
In that case d3.least is equivalent to d3.min. But I did have exactly that thought: instead of adding d3.least and d3.leastIndex, generalize d3.min to accept a comparator as well as an accessor, using function.length to disambiguate, and add d3.minIndex. |
Ah, right. We can’t generalize d3.min because it already passes the accessor three arguments: the value, the index and the array. So, we could generalize d3.least and d3.leastIndex, but it feels unnecessary if we also have the accessor-based d3.min and d3.minIndex. |
Okay, I’ve:
|
My suggestion is to add this notation: This is imo the most concise way of writing "give me an object that has the lowest foo". (An optional comparator could then be given as a second argument.) the code would be something like:
(and leastIndex should follow the same API) |
Ah, okay, that makes sense. Because unlike d3.min([{foo: 42}, {foo: 29}], a => a.foo) d3.least will return the element, not the value. |
Fixes #107.