src/helpers/stationHelpers.js
// Compare two stations by where they are in the train's route
Compare two stations by where they are in the train's route
Compare two stations by where they are in the train ' s route
function compareByLineOrder(lineOrder, a, b) {
  try {
    let aId = a['GTFS Stop ID'].toString();
    let bId = b['GTFS Stop ID'].toString();
    let aIndex = lineOrder.indexOf(aId);
    let bIndex = lineOrder.indexOf(bId);
    if (aIndex === -1) {
      throw `Station ${aId} not in line.`;
    }
    if (bIndex === -1) {
      throw `Station ${bId} not in line.`;
    }
    if (aIndex > bIndex) {
      return -1;
    }
    if (bIndex > aIndex) {
      return 1;
    }
    return 0;
  } catch (error) {
    console.log("⛔️ Error:", error)
    return error;
  }
}
function compareByLineOrder ( lineOrder , a , b ) { try { let aId = a [ 'GTFS Stop ID' ] . toString ( ) ; let bId = b [ 'GTFS Stop ID' ] . toString ( ) ; let aIndex = lineOrder . indexOf ( aId ) ; let bIndex = lineOrder . indexOf ( bId ) ; if ( aIndex === - 1 ) { throw ` ${ aId } ` ; } if ( bIndex === - 1 ) { throw ` ${ bId } ` ; } if ( aIndex > bIndex ) { return - 1 ; } if ( bIndex > aIndex ) { return 1 ; } return 0 ; } catch ( error ) { console . log ( "⛔️ Error:", er r r) return error ; } }
Compare two stations by where they are in the train's route
Compare two stations by where they are in the train ' s route
// Isolate GTFS Stop Id // Find index of GTFS Stop Id in line order // Throw error if either GTFS Stop Id is not found // Return sort order based on indexes