From: Stuart Little Date: 2009-02-12T06:40:32+09:00 Subject: Re: Array uniq Thanks for the response. I remove whitespace with gsub. My original data set: TueAug052008 WedAug062008 TueAug052008 WedAug062008 WedAug062008 Is returned after my code exactly the same, I am expecting WedAug062008 TueAug052008 I have dumbed the code down to see what you think: time = event.time_written.to_s dateCheck = [time.gsub(/\s/, '')[0..7] + time[26..29]] printdata = [dateCheck] @alerts.push printdata.uniq Many thanks David A. Black wrote: > On Thu, 12 Feb 2009, Stuart Little wrote: > >> therefore only have remaining after applying array.uniq to this array. >> It has become obvious this doesn't work and uniq doesn't remove any >> duplicates it just pushes the data out as it finds it full of >> dupelictes. Is this a problem with the data set? This is my code: >> >> value= timeDone.to_s >> dateCheck.push value.gsub(/\s/, '')[0..7] + value[26..30] >> date = dateCheck.uniq >> @alerts.push(date) > > Array#uniq does work: > >>> a = Array.new(4) { "TueAug052008" } > => ["TueAug052008", "TueAug052008", "TueAug052008", "TueAug052008"] >>> a.uniq > => ["TueAug052008"] > > So there must be something else going on. Maybe stray whitespace? How > are you determining that the operation didn't work? > > > David > > -- > David A. Black / Ruby Power and Light, LLC > Ruby/Rails consulting & training: http://www.rubypal.com > Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) > > http://www.wishsight.com => Independent, social wishlist management! -- Posted via http://www.ruby-forum.com/.