Ad
Code
Diff
  • 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
      end
    end
    
    • def twin_sum_solutions(array)
    • duplicates = []
    • find_duplicates(array).map{|e| e*2 }
    • end
    • def find_duplicates(array)
    • duplicates = []
    • array.each do |element|
    • duplicates << element if array.count(element) > 1
    • array.each_with_object([]) do |element, memo|
    • next if memo.include? element * 2
    • memo << element * 2 if array.count(element) > 1
    • end
    • duplicates.uniq
    • end
    • end