Merging array with same key - HELP

Hi ,    I need to merge an array in ruby on rails.

   array1 = ['01/01/2009','01/01/2009','10/01/2009','01/01/2009','10/01/2009']    array2 = ['1stjan1','1stjan2','10thjan1','1stjan3','10thjan2']

   I need to have array like this

   array3 = ['01/01/2009'=>'1stjan1-1stjan2-1stjan3','10/01/2009'=>'10thjan1-10thjan2']

  Thanks in Advance.

Haii… I will try help u. array3 = [‘01/01/2009’=>‘1stjan1-stjan2-1stjan3’,‘10/01/2009’=>‘10thjan1-10thjan2’] → this is not array… this is hash… The code is array3 = {} array1.each_with_index do |x, i| array3 = array2[i] end may be it can help u… thank you… fyi ==> array1.length == array2.length → this is rule for that case…(MUST)

make sure… array1 → date array2 → the value…

or array3 = {} array1.each_with_index do |x, i| array3 = array2[i] end

change to

array3 = {} array2.each_with_index do |x, i| array3 = array1[i] end

please try again

send to me the file… I will repair…

I think use: array3 = {}

array1.each_with_index do |x, i| array3 = array2[i]

end

Hi,

hash = {} array1.uniq.each { |d| hash[d] = } array1.each_with_index { |x,i| hash << array2[i] } hash.each_key { |key| hash[key] = hash[key].join('-') } hash.inspect # => {"01/01/2009"=>"1stjan1-1stjan2-1stjan3", "10/01/2009"=>"10thjan1-10thjan2"}

Enjoy,

-Harold

Hi,

hash = {} array1.uniq.each { |d| hash[d] = } array1.each_with_index { |x,i| hash << array2[i] } hash.each_key { |key| hash[key] = hash[key].join('-') } hash.inspect # => {"01/01/2009"=>"1stjan1-1stjan2-1stjan3", "10/01/2009"=>"10thjan1-10thjan2"}

Enjoy,

-Harold

Hi,

   I got a table like this

Hi,

I got a table like this

Which record do you want to include for the repeated dates? the first,
or last?

Julian

http://sensei.zenunit.com/ http://random8.zenunit.com/

all the records should be included.

Julian Leviston wrote: