From: "Peña, Botp" Date: 2007-10-30T14:41:45+09:00 Subject: Re: find the closest items in an array to a given value. ignore that post. what was i thinking, .. again? :)) kind regards -botp # -----Original Message----- # From: Peña, Botp [mailto:botp@delmonte-phil.com] # Sent: Tuesday, October 30, 2007 11:19 AM # To: ruby-talk ML # Subject: Re: find the closest items in an array to a given value. # # From: trebor777 [mailto:mrobert@trebor777.net] # # a = myhash.keys.sort[value-0.05..value+0.05] # # then i just use # # myhash[a[x]] # # can you test without hash? # # ~> a # => [1, 1.25, 1.9, 2, 3, 3.5] # ~> val # => 1.85 # ~> a[val-0.5..val+0.5] # => [1.25, 1.9] # ~> a.slice (val-0.5..val+0.5) # => [1.25, 1.9] # # kind regards -botp # #