Take two travel plans, combine them so that one is the first part of the journey of the other. We assume that the last station of the first travel plans is the first station of the second travel plans.
353173
function combineSearch(tp1, tp2) {
  return tp1.map(travelPlan => {
    let arrival = new Date(travelPlan.legs[travelPlan.legs.length - 1].arrival)
    let bestWaitTime = Infinity
    let bestTravelPlan2 = tp2[0]
    // Find the most appropriate corresponding second travel plan.
    for (let i = 0; i < tp2.length; i++) {
      let travelPlan2 = tp2[i]
      let departure = new Date(travelPlan2.legs[0].departure)
      let waitTime = departure - arrival
      if (waitTime > 0) {
        if (waitTime < bestWaitTime) {
          bestWaitTime = waitTime
          bestTravelPlan2 = travelPlan2
        }
      }
    }
    return {
      fares: combineFares(travelPlan.fares, bestTravelPlan2.fares),
      legs: travelPlan.legs.slice().concat(bestTravelPlan2.legs.slice()),
    }
  })
}
189690
def JoinPath(self, path_segments):
    
    # For paths on Windows we need to make sure to handle the first path
    # segment correctly.
    first_path_segment = None

    if path_segments and platform.system() == 'Windows':
      # Check if the first path segment contains a "special" path definition.
      first_path_segment = path_segments[0]
      first_path_segment_length = len(first_path_segment)
      first_path_segment_prefix = None

      # In case the path start with: \\.\C:\
      if (first_path_segment_length >= 7 and
          first_path_segment.startswith('\\\\.\\') and
          first_path_segment[5:7] == ':\\'):
        first_path_segment_prefix = first_path_segment[4:6]
        first_path_segment = first_path_segment[7:]

      # In case the path start with: \\.\ or \\?\
      elif (first_path_segment_length >= 4 and
            first_path_segment[:4] in ['\\\\.\\', '\\\\?\\']):
        first_path_segment_prefix = first_path_segment[:4]
        first_path_segment = first_path_segment[4:]

      # In case the path start with: C:
      elif first_path_segment_length >= 2 and first_path_segment[1] == ':':
        first_path_segment_prefix = first_path_segment[:2]
        first_path_segment = first_path_segment[2:]

      # In case the path start with: \\server\share (UNC).
      elif first_path_segment.startswith('\\\\'):
        prefix, _, remainder = first_path_segment[2:].partition(
            self.PATH_SEPARATOR)

        first_path_segment_prefix = '\\\\{0:s}'.format(prefix)
        first_path_segment = '\\{0:s}'.format(remainder)

      if first_path_segment_prefix:
        first_path_segment, _, remainder = first_path_segment.partition(
            self.PATH_SEPARATOR)

        if not remainder:
          _ = path_segments.pop(0)
        else:
          path_segments[0] = remainder

        first_path_segment = ''.join([
            first_path_segment_prefix, first_path_segment])

      else:
        first_path_segment = None

    # We are not using os.path.join() here since it will not remove all
    # variations of successive path separators.

    # Split all the path segments based on the path (segment) separator.
    path_segments = [
        segment.split(self.PATH_SEPARATOR) for segment in path_segments]

    # Flatten the sublists into one list.
    path_segments = [
        element for sublist in path_segments for element in sublist]

    # Remove empty path segments.
    path_segments = list(filter(None, path_segments))

    if first_path_segment is None:
      path = '{0:s}{1:s}'.format(
          self.PATH_SEPARATOR, self.PATH_SEPARATOR.join(path_segments))
    else:
      path = first_path_segment
      if path_segments:
        path = '{0:s}{1:s}{2:s}'.format(
            path, self.PATH_SEPARATOR, self.PATH_SEPARATOR.join(path_segments))

    return path
1274907
function _addTrip(trip) {

    // Make sure trip isn't already in list
    let found = false;
    for ( let i = 0; i < rtn.length; i++ ) {
      if ( rtn[i].id === trip.id ) {
        found = true;
      }
    }

    // Process new trip
    if ( !found ) {

      // Make sure the trip stops at any of the next stops, after the current stop
      let stopFound = false;
      let add = false;
      for ( let i = 0; i < trip.stopTimes.length; i++ ) {
        let stopId = trip.stopTimes[i].stop.id;
        if ( !stopFound && stopId === stop.id ) {
          stopFound = true;
        }
        else if ( stopFound ) {
          if ( nextStops.indexOf(stopId) > -1 ) {
            add = true;
            i = trip.stopTimes.length;
          }
        }
      }

      // Add Trip
      if ( add ) {
        rtn.push(trip);
      }

    }

  }
536483
function () {
            var first = Math.max(0, Math.min(this.value[0], this.value[1], 1));
            var second = Math.min(1, Math.max(this.value[0], this.value[1], 0));
            this._savedX1 = Math.floor(first * this._railWidth);
            this._savedX2 = Math.ceil(second * this._railWidth + this._firstWidth);
        }
1053771
function(points, firstPoint, lastPoint, tolerance){
                var maxDistance = 0;
                var indexFarthest = 0;
    
                for (var index = firstPoint, distance; index < lastPoint; index++) {
                    distance = perpendicularDistance(points[firstPoint], points[lastPoint], points[index]);
                    if (distance > maxDistance) {
                        maxDistance = distance;
                        indexFarthest = index;
                    }
                }
    
                if (maxDistance > tolerance && indexFarthest != firstPoint) {
                    //Add the largest point that exceeds the tolerance
                    pointIndexsToKeep.push(indexFarthest);
                    douglasPeuckerReduction(points, firstPoint, indexFarthest, tolerance);
                    douglasPeuckerReduction(points, indexFarthest, lastPoint, tolerance);
                }
            }
303494
public static boolean checkpointsMatch(
		Collection<CompletedCheckpoint> first,
		Collection<CompletedCheckpoint> second) {
		if (first.size() != second.size()) {
			return false;
		}

		List<Tuple2<Long, JobID>> firstInterestingFields = new ArrayList<>(first.size());

		for (CompletedCheckpoint checkpoint : first) {
			firstInterestingFields.add(
				new Tuple2<>(checkpoint.getCheckpointID(), checkpoint.getJobId()));
		}

		List<Tuple2<Long, JobID>> secondInterestingFields = new ArrayList<>(second.size());

		for (CompletedCheckpoint checkpoint : second) {
			secondInterestingFields.add(
				new Tuple2<>(checkpoint.getCheckpointID(), checkpoint.getJobId()));
		}

		return firstInterestingFields.equals(secondInterestingFields);
	}
950386
def setStation(self, number):
        
        # If we press up at the first station, we go to the last one
        # and if we press down on the last one we go back to the first one.
        if number < 0:
            number = len(self.stations) - 1
        elif number >= len(self.stations):
            number = 0

        self.selection = number

        maxDisplayedItems = self.bodyMaxY - 2
        if self.selection - self.startPos >= maxDisplayedItems:
            self.startPos = self.selection - maxDisplayedItems + 1
        elif self.selection < self.startPos:
            self.startPos = self.selection
304758
def join(path1, path2):
    '''
    
    '''
    if path1.endswith('/') and path2.startswith('/'):
        return ''.join([path1, path2[1:]])
    elif path1.endswith('/') or path2.startswith('/'):
        return ''.join([path1, path2])
    else:
        return ''.join([path1, '/', path2])
523204
public void combine(DoubleSummaryStatistics other) {
        count += other.count;
        simpleSum += other.simpleSum;
        sumWithCompensation(other.sum);
        sumWithCompensation(other.sumCompensation);
        min = Math.min(min, other.min);
        max = Math.max(max, other.max);
    }
1179480
private static void mergeInto(double[] first, double[] second) {
        for (int j = 0; j < first.length / 2; j++) {
            first[j] = Math.min(first[j], second[j]);
            first[j + first.length / 2] = Math.max(first[j + first.length / 2], second[j + first.length / 2]);
        }
    }
114948
def merge_resources(resource1, resource2):
    
    merged = resource1.copy()
    merged.update(resource2)
    return merged
739547
private static Collection<JobIdWithStatus> combine(
			Collection<JobIdWithStatus> first,
			Collection<JobIdWithStatus> second) {
		checkNotNull(first);
		checkNotNull(second);

		ArrayList<JobIdWithStatus> result = new ArrayList<>(first.size() + second.size());

		result.addAll(first);
		result.addAll(second);

		return result;
	}
190646
public static String combinePaths(String first, String... other) {
        return Paths.get(first, other).toString();
    }
1038772
def merge(a, b):
    
    _check_steps(a, b)
    return range(min(a.start, b.start), max(a.stop, b.stop))
123596
function extractTravelPlan(data) {
  let plans = []
  let getPlan = searchPlan => plans.find(plan => samePlan(plan, searchPlan))

  data.folders.forEach(folder => {
    let cents = folder.cents
    if (folder.cents === undefined) { return }
    let from = stationDataFromId(folder.departure_station_id, data)
    let to = stationDataFromId(folder.arrival_station_id, data)
    let departure = (new Date(folder.departure_date)).toISOString()
    let arrival = (new Date(folder.arrival_date)).toISOString()

    let tripId = folder.trip_ids[0]
    let trip = data.trips.find(trip => trip.id === tripId)
    let segments = trip.segment_ids.map(segmentId =>
      data.segments.find(segment => segment.id === segmentId)
    )
    let legs = segments.map(segment => ({
      from: stationDataFromId(segment.departure_station_id, data),
      to: stationDataFromId(segment.arrival_station_id, data),
      departure: (new Date(segment.departure_date)).toISOString(),
      arrival: (new Date(segment.arrival_date)).toISOString(),
    }))
    let searchPlan = {fares: [], legs}
    let plan = getPlan(searchPlan)

    if (plan === undefined) {
      plan = searchPlan
      plans.push(plan)

    } else if
      // If that price is already in the plan, no need to add to it.
      (plan.fares.find(fare => fare.price[0].cents === cents) !== undefined) {
      return
    }


    plan.fares.push({
      price: [{ cents: folder.cents, currency: folder.currency }],
      class: travelClass(folder.travel_class),
      flexibility: flexibility(folder.flexibility),
    })
  })
  return plans
}
1052089
public static final double departure(WayPoint loc1, WayPoint loc2)
    {
        return departure(loc2.getLatitude(), loc1.getLatitude());
    }
1095366
function mergeTimes(source, destination) {
  if(source.hasOwnProperty('earliestDecodingTime')) {
    if(destination.hasOwnProperty('earliestDecodingTime')) {
       let isSourceEarlier = (source.earliestDecodingTime <
                              destination.earliestDecodingTime);
       if(isSourceEarlier) {
         destination.earliestDecodingTime = source.earliestDecodingTime;
       }
    }
    else {
      destination.earliestDecodingTime = source.earliestDecodingTime;
    }
  }
}