On 11/23/12, dsmith <d...@nomail.com> wrote: > What is the best way to have a function sort an associative array > by key? The following yields a conversion error. > > double[string] aa_sort(double[string] aa) { > return aa.keys.sort; > }
Hashes are unordered, you can't sort them by key because they don't preserve any order during insertion/removal. You can alternatively return a sorted array: string[] keys_sorted(double[string] aa) { string[] keys = aa.keys; sort(keys); // from std.algorithm; return keys; }