modules/search/search.js
function _cleanArrivals(results) {
    // List of Arrivals to Keep
    let arrivals = [];

    // Get unique arrivals
    let arrivalTimes = [];
    for ( let i = 0; i < results.length; i++ ) {
      if ( arrivalTimes.indexOf(results[i].destination.arrival.toTimestamp()) === -1 ) {
        arrivalTimes.push(results[i].destination.arrival.toTimestamp());
      }
    }

    // Pick best Trip for each arrival
    for ( let i = 0; i < arrivalTimes.length; i++ ) {
      let arrivalTime = arrivalTimes[i];
      let arrival = undefined;

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

      // Add arrival to list
      arrivals.push(arrival);

    }

    // Return arrivals
    return arrivals;
  }
function _cleanArrivals(results) {
    // List of Arrivals to Keep
    let arrivals = [];

    // Get unique arrivals
    let arrivalTimes = [];
    for ( let i = 0; i < results.length; i++ ) {
      if ( arrivalTimes.indexOf(results[i].destination.arrival.toTimestamp()) === -1 ) {
        arrivalTimes.push(results[i].destination.arrival.toTimestamp());
      }
    }

    // Pick best Trip for each arrival
    for ( let i = 0; i < arrivalTimes.length; i++ ) {
      let arrivalTime = arrivalTimes[i];
      let arrival = undefined;

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

      // Add arrival to list
      arrivals.push(arrival);

    }

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