ruby - How do I create a diff of hashes with a correction factor? -


i want compare hashes inside array:

h_array = [   {:name => "john", :age => 23, :eye_color => "blue"},   {:name => "john", :age => 22, :eye_color => "green"},   {:name => "john", :age => 22, :eye_color => "black"} ]  get_diff(h_array, correct_factor = 2) # should return [{:eye_color => "blue"}, {:eye_color => "green"}, {:eye_color => "black"}]  get_diff(h_array, correct_factor = 3) # should return  # [[{:age => 23}, {:age => 22}, {:age => 22}],  # [{:eye_color => "blue"}, {:eye_color => "green"}, {:eye_color => "black"}]] 

i want diff hashes contained in h_array. looks recursive call/method because h_array can have multiple hashes same number of keys , values. how can implement get_diff method?

def get_diff h_array, correct_factor   h_array.first.keys.reject{|k|     h_array.map{|h| h[k]}.sort.chunk{|e| e}.map{|_,e| e.size}.max >= correct_factor   }.map{|k|     h_array.map{|hash| hash.select{|key,_| k == key}}   } end 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -