From: Brian Candler Date: 2011-02-05T18:17:26+09:00 Subject: Re: Determining uniqueness on a single array element James Byrne wrote in post #979694: > Now I wish to ensure that each distinct hexdigest is processed but once. > I can do this: > > hex_array = [] > outer_array.each do |inner_array| > next if hex_array.include?( inner_array[2] ) > hex_array << inner_array[2] > . . . > > I wonder if there is a better way? Any suggestions? (1) auto-splat to avoid the [2] magic index outer_array.each do |mtime, name, hexdigest| (2) Use a hash, rather than an array, to record ones you've processed. This avoids a linear search on every iteration seen = {} outer_array.each do |mtime, name, hexdigest| next if seen[hexdigest] seen[hexdigest] = true ... end -- Posted via http://www.ruby-forum.com/.