Ruby invert hash

Hi all,

This is how to invert hash manually.

path_names = {:glass=>"gelas", :metals=>"", :other=>"lainnya", :papers=>"kertas", :plastics=>"plastik"}
new_names = path_names.inject({}) { |h, (k, v)| h[v] = k; h }


The result:

{"gelas"=>:glass, "lainnya"=>:other, "kertas"=>:papers, "plastik"=>:plastics}


Komentar

Postingan populer dari blog ini

EPrT English Proficiency Test Soal - soal

cara memunculkan dan menyembunyikan icon date, time, clock, volume, network, power battery, action center pada taskbar pada Windows 7