I need to find the distance between the 2nd and 3rd elements of each nested element so
nested_array = [[0, 3, 4], [1, 20, 21], [2, 2, 2]]
def pythag_theorem(a, b)
c = (a * a) + (b * b)
result = Math.sqrt(c)
result
end
def find_distance(array)
t = 0
while t < array.length
array[t].map! {|x| pythag_theorem(x[1], x[2])}
t += 1
end
array
end
print find_distance(nested_array)
I'm getting
[[0.0, 1.4142135623730951, 0.0], [1.0, 0.0, 1.0], [1.0, 1.0, 1.0]]
when I need
[[0, 5], [1, 29], [2, 2.82842712474619]]
pythag_theorem works but why isn't map! working for me? Thanks.