modules/search/search.js
function _cleanDepartures(results) {
    // List of Departures to Keep
    let departures = [];

    // Get unique departures
    let departureTimes = [];
    for ( let i = 0; i < results.length; i++ ) {
      if ( departureTimes.indexOf(results[i].origin.departure.toTimestamp()) === -1 ) {
        departureTimes.push(results[i].origin.departure.toTimestamp());
      }
    }

    // Pick best Trip for each departure
    for ( let i = 0; i < departureTimes.length; i++ ) {
      let departureTime = departureTimes[i];
      let departure = undefined;

      // Get Trips with departure time
      for ( let j = 0; j < results.length; j++ ) {
        let result = results[j];
        if ( result.origin.departure.toTimestamp() === departureTime ) {
          if ( departure === undefined )  {
            departure = result;
          }
          else if ( result.destination.arrival.toTimestamp() < departure.destination.arrival.toTimestamp() ) {
            departure = result;
          }
          else if ( result.destination.arrival.toTimestamp() === departure.destination.arrival.toTimestamp() && result.length < departure.length ) {
            departure = result;
          }
        }
      }

      // Add departure to list
      departures.push(departure);
    }

    // Return departures
    return departures;
  }
function _cleanDepartures(results) {
    // List of Departures to Keep
    let departures = [];

    // Get unique departures
    let departureTimes = [];
    for ( let i = 0; i < results.length; i++ ) {
      if ( departureTimes.indexOf(results[i].origin.departure.toTimestamp()) === -1 ) {
        departureTimes.push(results[i].origin.departure.toTimestamp());
      }
    }

    // Pick best Trip for each departure
    for ( let i = 0; i < departureTimes.length; i++ ) {
      let departureTime = departureTimes[i];
      let departure = undefined;

      // Get Trips with departure time
      for ( let j = 0; j < results.length; j++ ) {
        let result = results[j];
        if ( result.origin.departure.toTimestamp() === departureTime ) {
          if ( departure === undefined )  {
            departure = result;
          }
          else if ( result.destination.arrival.toTimestamp() < departure.destination.arrival.toTimestamp() ) {
            departure = result;
          }
          else if ( result.destination.arrival.toTimestamp() === departure.destination.arrival.toTimestamp() && result.length < departure.length ) {
            departure = result;
          }
        }
      }

      // Add departure to list
      departures.push(departure);
    }

    // Return departures
    return departures;
  }
function _cleanDepartures ( results ) { // List of Departures to Keep let departures = [ ] ; // Get unique departures let departureTimes = [ ] ; for ( let i = 0 ; i < results . length ; i ++ ) { if ( departureTimes . indexOf ( results [ i ] . origin . departure . toTimestamp ( ) ) === - 1 ) { departureTimes . push ( results [ i ] . origin . departure . toTimestamp ( ) ) ; } } // Pick best Trip for each departure for ( let i = 0 ; i < departureTimes . length ; i ++ ) { let departureTime = departureTimes [ i ] ; let departure = undefined ; // Get Trips with departure time for ( let j = 0 ; j < results . length ; j ++ ) { let result = results [ j ] ; if ( result . origin . departure . toTimestamp ( ) === departureTime ) { if ( departure === undefined ) { departure = result ; } else if ( result . destination . arrival . toTimestamp ( ) < departure . destination . arrival . toTimestamp ( ) ) { departure = result ; } else if ( result . destination . arrival . toTimestamp ( ) === departure . destination . arrival . toTimestamp ( ) && result . length < departure . length ) { departure = result ; } } } // Add departure to list departures . push ( departure ) ; } // Return departures return departures ; }
Pick best Trip with equal departures
@param results
@returns {Array}
@private
Pick best Trip with equal departures