79297197

Date: 2024-12-20 12:19:12
Score: 1
Natty:
Report link

It isn't so hard at all:

>> numstrs = %w(zero one two three four)
=> ["zero", "one", "two", "three", "four"]
>> numints = (0..4).to_a
=> [0, 1, 2, 3, 4]
>> combarr = numints.zip(numstrs)
=> [[0, "zero"], [1, "one"], [2, "two"], [3, "three"], [4, "four"]]
>> combhash = combarr.to_h
=> {0=>"zero", 1=>"one", 2=>"two", 3=>"three", 4=>"four"}
>> invhash = combhash.values.zip(combhash.keys).to_h
=> {"zero"=>0, "one"=>1, "two"=>2, "three"=>3, "four"=>4}
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: some one