Topic: how to sum the 2 largest elements in an array
I have a method, in which I have created an array of numbers, I want to sum the two largest elements of the array, which I thought worked fine until I moved the numbers around.
def max_2_sums
array = [3, 4, 5]
array.sort!
num_1 = array.max
num_2 = array.length-1
max_2_sum = 0
array.each do |item|
max_2_sum = num_1 + num_2
end
puts max_2_sum
end
what have I done wrong?