Clean the list of Trip Search Results
- sort by departure date/time
- pick best trip that leaves/arrives at same time
- remove excessively long trips
@param {TripSearchResult[]} results
@returns {TripSearchResult[]} clean results
@private
166958
function _cleanResults(results) {

  // Clean up departures
  results = _cleanDepartures(results);

  // Clean up arrivals
  results = _cleanArrivals(results);

  // Sort By Departure Time
  results.sort(TripSearchResult.sortByDeparture);

  // Return results
  return results;


  /**
   * Pick best Trip with equal departures
   * @param results
   * @returns {Array}
   * @private
   */
  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 arrivals
   * @param results
   * @returns {Array}
   * @private
   */
  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;
  }

}
745398
function(arrays,result){
       var self = this,flat = result || [];
       this.forEach(arrays,function(a){

        if(self.isArray(a)){
         self.flatten(a,flat);
       }else{
         flat.push(a);
       }

     },self);

       return flat;
    }
738752
private function processHitResultsRecurse($results, $prefix=null) {
        if(!is_array($results)) {
            return [$prefix => $results];
        }

        $ret = [];
        foreach($results as $key=>$result) {
            // Flatten arrays.
            $sub_prefix = is_null($prefix) ? $key:"$prefix.$key";
            $ret = array_merge($ret, $this->processHitResultsRecurse($result, $sub_prefix));
        }
        return $ret;
    }
337426
private List<?> toList(Object results)
    {
        if (results instanceof Object[])
        {
            return Arrays.asList( (Object[]) results );
        }
        if (results instanceof Collection)
        {
            return new ArrayList<Object>( (Collection<?>) results );
        }
        return null;
    }
876482
private void closeAndForgetOldResults() {
        Iterator<FieldSearchResultSQLImpl> iter =
                m_currentResults.values().iterator();
        while (iter.hasNext()) {
            FieldSearchResultSQLImpl r = iter.next();
            if (r.isExpired()) {
                logger.debug("listSession " + r.getToken()
                        + " expired; will forget it.");
                iter.remove();
            }
        }
    }
115451
function getResults(result, objects) {
		
		// if there are no results, resolve an empty array
		if (!result) {
			return new Promise(function(resolve, reject) {
				resolve([]);
			});
		}
		
		// if the result object is undefined or not an array, make it one
		result.objects = result.objects || [];
		result.objects = Array.isArray(result.objects) ? result.objects : [result.objects];
		objects        = _.union(objects, result.objects);
		
		// if the result has a token, there are more results, continue to get them
		if (result.token) {
			return _client.method('ContinueRetrievePropertiesEx', {
				_this: _client._sc.propertyCollector,
				token: result.token
			})
			.then(function(results) {
				return getResults(results, objects);
			});
		}
		
		// if there are no more results, return the formatted results
		else {
			return new Promise(function(resolve, reject) {
				resolve(env.format(objects));
			});
		}
	}
426212
function() {
      if (!this.routes) { 
        return;
      }
      var routes = [];
      for (var route in this.routes) {
        if (this.routes.hasOwnProperty(route)) {
          routes.unshift([route, this.routes[route]]);
        }
      }
      for (var i = 0, l = routes.length; i < l; i++) {
        this.route(routes[i][0], routes[i][1], this[routes[i][1]]);
      }
    }
519134
function clear() {
        var that = this;
        var state = getInternalState(that);
        var data = state.index;
        var entry = state.first;
        while (entry) {
          entry.removed = true;
          if (entry.previous) entry.previous = entry.previous.next = undefined;
          delete data[entry.index];
          entry = entry.next;
        }
        state.first = state.last = undefined;
        if (DESCRIPTORS) state.size = 0;
        else that.size = 0;
      }
1353097
function cleanRes (res) {
    return {
        body: res.body,
        rawHeaders: res.rawHeaders,
        statusCode: res.statusCode,
    }
}
725180
public void resetResult(Object result)
  {

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "resetResult");

    if (result != null)
       ((TopicAclTraversalResults) result).reset();
    //   ((ArrayList) result).clear();

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "resetResult");

  }
1019716
private static function clearNonMatched($match_results){
    return array_filter($match_results, function($el){
      $keep = true;
      if($el === "" || (is_array($el) && empty($el))|| $el === null|| $el === array("")){
        $keep = false;
      }

      return $keep;
    });
  }
655553
public static String cleanUpResults(String resultsToClean)
    {
        if(resultsToClean != null)
        {
            String cleanedString = resultsToClean.replace("</html><html>", "<br/><br/>");
            cleanedString = cleanedString.replace("</HTML><HTML>", "<br/><br/>");
            cleanedString = cleanedString.replace("<html>", "");
            cleanedString = cleanedString.replace("</html>", "");
            cleanedString = cleanedString.replace("<HTML>", "");
            cleanedString = cleanedString.replace("</HTML>", "");
            cleanedString = cleanedString.replace("<body>", "");
            cleanedString = cleanedString.replace("</body>", "");
            cleanedString = cleanedString.replace("<BODY>", "");
            cleanedString = cleanedString.replace("</BODY>", "");
            return cleanedString;
        }
        
        return null;
    }
851711
function(array) {
    this.destination = this.parse(array)

    // normalize length of arrays
    if (this.value.length != this.destination.length) {
      var lastValue       = this.value[this.value.length - 1]
        , lastDestination = this.destination[this.destination.length - 1]

      while(this.value.length > this.destination.length)
        this.destination.push(lastDestination)
      while(this.value.length < this.destination.length)
        this.value.push(lastValue)
    }

    return this
  }
711725
function() {
    this._latlngs = [];
    this._resultsModel = null;
    this._measureVertexes.clearLayers();
    if (this._measureDrag) {
      this._layer.removeLayer(this._measureDrag);
    }
    if (this._measureArea) {
      this._layer.removeLayer(this._measureArea);
    }
    if (this._measureBoundary) {
      this._layer.removeLayer(this._measureBoundary);
    }
    this._measureDrag = null;
    this._measureArea = null;
    this._measureBoundary = null;
  }
745026
function(results) {        
        for(var i = 0; i < results.rows.length; i++) {
            console.log("Result " + (i + 1) + ": ");
            var row = results.rows[i];
            for(var j = 0; j < results.fields.length; j++) {
                var field = results.fields[j];
                var value = row[j];
                
                console.log("  " + field + " = " + value);
            }
        }
    }
1092656
public function prune(array $results)
    {
        $mean = array_sum($results) / count($results);
        $deviation = $this->deviations * $this->standardDeviation($results);
        $lower = $mean - $deviation;
        $upper = $mean + $deviation;

        return array_values(array_filter($results, function ($val) use ($lower, $upper) {
                return $val >= $lower && $val <= $upper;
            }));
    }
1255907
def clear(self, results=True, errors=True):
        '''
        
        '''
        if results:
            self.results = []
        if errors:
            self.errors = []