def twin_sum_solutions(array) array.tally.each_pair.with_object([]) do | (v, count), res | res << v * 2 if count == 2 end end
- def twin_sum_solutions(array)
array.each_with_object([]) do |element, memo|next if memo.include? element * 2memo << element * 2 if array.count(element) > 1- array.tally.each_pair.with_object([]) do | (v, count), res |
- res << v * 2 if count == 2
- end
- end