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
If you think with Ruby's syntax in mind, just take a transpose and take out all arrivals from departures.
def flight_origin(arr) plan = arr.transpose plan[0].index((plan[0] - plan[1])[0]) end flight_origin([['LAX', 'BWI'], ['BOS', 'SEA'], ['HNL', 'LAX'], ['SEA', 'HNL']]) # => 1
HTH