# Given an array_of_ints, find the highest_product you can get from three of the integers. # The input array_of_ints will always have at least three integers. def highest_product(arr) highest = arr[0] lowest = arr[0] highest_of_two = arr[0] * arr[1] highest_of_three = arr[0] * arr[1] * arr[2] arr.each_with_index do |current, index| highest_of_three = [highest_of_three, (highest_of_two * current)].max highest_of_two = [highest_of_two, (current * highest)].max highest = [highest, current].max puts "current = #{current} & highest = #{highest} & highest_of_two = #{highest_of_two} & highest_of_three = #{highest_of_three}" end highest_of_three end def assert_equal(actual, expected) puts "Expected: #{expected} and got #{actual}" unless actual == expected end assert_equal(highest_product([1,4,5,3,6]), 120) assert_equal(highest_product([1,10,1,-5,1,-100]), 10)