Input:-
array = [{"name"=>"id", "value"=>"123"},
{"name"=>"type", "value"=>"app"},
{"name"=>"codes", "value"=>"12"},
{"name"=>"codes", "value"=>"345"},
{"name"=>"type", "value"=>"app1"}]
sample_hash = {}
Function:-
array.map {|f| sample_hash[f["name"]] = sample_hash[f["value"]] }
Result:-
sample_hash
=> {"id"=>"123", "type"=>"app", "codes"=>"345"}
But i need expected result should be like below:-
sample_hash
=> {"id"=>"123", "type"=>["app","app1"], "codes"=>["12", "345"]}
How can i get my expected output?
"id" => ["123"]- that way when getting values from the hash you won't have to check if you have got back a string or an array.