Ruby - Hash - Combination -
i have hash 5 elements, instance:
my_hash = {a: 'qwe', b: 'zcx', c: 'dss', d: 'ccc', e: 'www' }
my goal return every time in loop hash without 1 element like:
my_hash = {a: 'qwe', b: 'zcx', c: 'dss', d: 'ccc' }
then
my_hash = {a: 'qwe', b: 'zcx', c: 'dss', e: 'www' }
and on
using array use combination method when use hash? possible
you can convert array , convert hash later:
my_hash.to_a.combination(4).to_a.sample.to_h # => {:a=>"qwe", :b=>"zcx", :c=>"dss", :e=>"www"} my_hash.to_a.combination(4).to_a.sample.to_h # => {:a=>"qwe", :c=>"dss", :d=>"ccc", :e=>"www"}
Comments
Post a Comment