I am attempting to sort an array of weapons by id AND element. For example, all weapons with an element of 13 would be grouped together in the array, but be sorted by id within that group. Then next would come all the element 14s sorted by id. So, I have this slice of code:
It sorts fine by element. How would I implement ids into the picture? Thanks in advance.
Code:
@data.sort! {|a, b|
for i in 13..18
if a.element_set.include?(i)
item_a = i - 12
end
if b.element_set.include?(i)
item_b = i - 12
end
end
item_a <=> item_b
}
It sorts fine by element. How would I implement ids into the picture? Thanks in advance.