Max/Min values in an associative array
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Aug 14 05:59:48 PDT 2014
TJB:
> 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.
void main() {
import std.stdio, std.algorithm;
double[char] bids = ['A': 37.50,
'B': 38.11,
'C': 36.12];
bids.byValue.reduce!(min, max).writeln;
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list