how to get top N distinct elements from range?
Jacob Carlborg
doob at me.com
Fri Mar 8 12:53:03 PST 2013
On 2013-03-08 14:33, Andrea Fontana wrote:
> I wonder if exists a way to get top n distinct elements from a range
> (infinite too!)
>
> A (not efficient) way to to this is range.array.sort.uniq.take(n) but
> it's a bit overkill, it sorts elements, and of course doesn't work with
> infinite ranges. Am i missing any function?
There's a function called "topN" in std.algorithm, I don't know if
that's what you're looking for.
http://dlang.org/phobos/std_algorithm.html#topN
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list