Logo

Programming-Idioms

History of Idiom 113 > diff from v17 to v18

Edit summary for version 18 by :
New Ruby implementation by user [steenslag]

Version 17

2016-02-18, 16:58:03

Version 18

2016-04-06, 20:40:48

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

Code
h.sort_by{|k,x| x}.each{|k,x| puts "#{k}: #{x}"}