I am trying to solve a problem where I need to find the airport code in an array of arrays of that represents the starting point of a multi-city flight plan. For example: Given an array [['LAX', 'BWI'], ['BOS', 'SEA'], ['HNL', 'LAX'], ['SEA', 'HNL']] where the first index of each sub array is the departing airport and the second is the destination airport, I need to find the index point where the flight originates, in this case the method would return 1 to represent ['BOS', 'SEA'].
This code does not work and always returns the last element in the array
def find_start_point(list)
start_point = nil
list.each do |a|
list.each do |b|
if a[0] != b[1]
start_point = list.index(a)
end
end
end
start_point
end