Max/Min values in an associative array

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 6 11:05:28 PDT 2014


On Wed, Aug 06, 2014 at 05:57:54PM +0000, TJB via Digitalmars-d-learn wrote:
> I am trying to find the max and min values in an associative array. Say I
> have:
> 
> double[char] bids;
> bid['A'] = 37.50;
> bid['B'] = 38.11;
> bid['C'] = 36.12;
> 
> How can I find the max and min values. I am thinking that I need to use max
> and min functions from std.algorithm, but not sure how to.
[...]

	import std.algorithm : reduce, max, min;

	auto highest = reduce!((a,b) => max(a,b))(-double.max, bids.byValue());
	auto lowest = reduce!((a,b) => min(a,b))(double.max, bids.byValue());


T

-- 
Designer clothes: how to cover less by paying more.


More information about the Digitalmars-d-learn mailing list