Ad
Code
Diff
  • 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 * 2
    • memo << 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