Hi! the array is like this [[1,"h"],[2,"g"]] i want to select the parts of the array with the minimum value and show the 2nd part of the element only meaning the strings like "h" and "g" i''ve tried this but it doesn''t work x.select{|c| c.first = [x.min{|a,b| a.first <=> b}.first]}.last and i get comparison of Array with Array failed --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok i managed to get this out smallest = x.min{|x,y| x[0] <=> y[0]}[0] result = x.select{|g| g[0] == smallest}.map{|g|g[1]} and it works but the problem is when i apply it to my app because [[1,"h"],[2,"g"]] is actually [[groceries.price,"h"]] and it gives undefined method `[]'' for #<BigDecimal:b69b1e44,''0.3E1'',4(8)> meaning that theres something wrong with groceries.price but in the migration file .price is specified to be t.decimal :price, :precision => 8, :scale => 2 I don''t understand why rails is giving an undefined method when i subsitute in decimals for 1 and 2 in the array it is ok. On Sep 6, 8:00 pm, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi! > > the array is like this > [[1,"h"],[2,"g"]] > i want to select the parts of the array with the minimum value > and show the 2nd part of the element only meaning the strings like "h" > and "g" > > i''ve tried this but it doesn''t work > x.select{|c| c.first = [x.min{|a,b| a.first <=> b}.first]}.last > > and i get comparison of Array with Array failed--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Solved should not use x for block variable -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of tyliong Sent: Saturday, September 06, 2008 8:37 PM To: Ruby on Rails: Talk Subject: [Rails] Re: nested array .select statment ok i managed to get this out smallest = x.min{|x,y| x[0] <=> y[0]}[0] result = x.select{|g| g[0] == smallest}.map{|g|g[1]} and it works but the problem is when i apply it to my app because [[1,"h"],[2,"g"]] is actually [[groceries.price,"h"]] and it gives undefined method `[]'' for #<BigDecimal:b69b1e44,''0.3E1'',4(8)> meaning that theres something wrong with groceries.price but in the migration file .price is specified to be t.decimal :price, :precision => 8, :scale => 2 I don''t understand why rails is giving an undefined method when i subsitute in decimals for 1 and 2 in the array it is ok. On Sep 6, 8:00 pm, tyliong <tyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi! > > the array is like this > [[1,"h"],[2,"g"]] > i want to select the parts of the array with the minimum value > and show the 2nd part of the element only meaning the strings like "h" > and "g" > > i''ve tried this but it doesn''t work > x.select{|c| c.first = [x.min{|a,b| a.first <=> b}.first]}.last > > and i get comparison of Array with Array failed--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---