I have an array of objects and want to build an unique array by the attribute "position", like
boxes.to_a.uniq! {|p| p[:position] }
but i want to distinguish before throwing all the doubles away, if the second attribute "mismatch" is equal or higher. For example i have:
{ position: 233, mismatch: 3},
{ position: 234, mismatch: 3},
{ position: 233, mismatch: 1}
and in the end i'd like to keep the one with less mismatch:
{ position: 234, mismatch: 3},
{ position: 233, mismatch: 1}
because position was the same in object 1 and 3, but mismatch was less in the last object.
Edit: boxes is an array of objects and i build it like that:
@boxes = []
...
@boxes << {
:position => i,
:mismatch => mm,
}
where position and mismatch is calculated over a DNA sequence. The mismatch represents the hamming distance to a 9-nucleotide motif ( string like "TTGATGCTT" )
boxesoriginally? Hashes can't have duplicate keys anyways, so this is a bit confusing.