Sort segments by distance, helper function
@param {SegmentData} a The first segment data.
@param {SegmentData} b The second segment data.
@return {number} The difference in distance.
@this {Snap}
424466
function sortByDistance(a, b) {
  const deltaA = squaredDistanceToSegment(this.pixelCoordinate_, a.segment);
  const deltaB = squaredDistanceToSegment(this.pixelCoordinate_, b.segment);
  return deltaA - deltaB;
}
500862
function sortByDate(a, b) {
    return new Date(a.added).getTime() - new Date(b.added).getTime();
  }
901874
function sortRankedItems(a, b) {
  const aFirst = -1
  const bFirst = 1
  const {rank: aRank, index: aIndex, keyIndex: aKeyIndex} = a
  const {rank: bRank, index: bIndex, keyIndex: bKeyIndex} = b
  const same = aRank === bRank
  if (same) {
    if (aKeyIndex === bKeyIndex) {
      return aIndex < bIndex ? aFirst : bFirst
    } else {
      return aKeyIndex < bKeyIndex ? aFirst : bFirst
    }
  } else {
    return aRank > bRank ? aFirst : bFirst
  }
}
620356
function comparator(a, b) {
    var aHasIndex = a.hasOwnProperty('index'),
        bHasIndex = b.hasOwnProperty('index');

    if (aHasIndex) {
      if (bHasIndex) {
        if (a.index != b.index) {
          return a.index - b.index;
        }
      }
      else {
        return -1;
      }
    }

    else if (bHasIndex) {
      return 1;
    }

    var aHasTimestamp = a.hasOwnProperty('timestamp'),
        bHasTimestamp = b.hasOwnProperty('timestamp');

    if (aHasTimestamp) {
      if (bHasTimestamp) {
        if (a.timestamp != b.timestamp) {
          return b.timestamp - a.timestamp;
        }
      }
      else {
        return -1;
      }
    }

    else if (bHasTimestamp) {
      return 1;
    }
    
    return a.name > b.name ? 1 : -1;
  }
915281
function compareCells(a, b) {
  var n = a.length
    , t = a.length - b.length
    , min = Math.min
  if(t) {
    return t
  }
  switch(n) {
    case 0:
      return 0;
    case 1:
      return a[0] - b[0];
    case 2:
      var d = a[0]+a[1]-b[0]-b[1]
      if(d) {
        return d
      }
      return min(a[0],a[1]) - min(b[0],b[1])
    case 3:
      var l1 = a[0]+a[1]
        , m1 = b[0]+b[1]
      d = l1+a[2] - (m1+b[2])
      if(d) {
        return d
      }
      var l0 = min(a[0], a[1])
        , m0 = min(b[0], b[1])
        , d  = min(l0, a[2]) - min(m0, b[2])
      if(d) {
        return d
      }
      return min(l0+a[2], l1) - min(m0+b[2], m1)
    
    //TODO: Maybe optimize n=4 as well?
    
    default:
      var as = a.slice(0)
      as.sort()
      var bs = b.slice(0)
      bs.sort()
      for(var i=0; i<n; ++i) {
        t = as[i] - bs[i]
        if(t) {
          return t
        }
      }
      return 0
  }
}
224597
public static final double distance(final Point2D a, final Point2D b)
    {
        return Point2DJSO.distance(a.getJSO(), b.getJSO());
    }
867235
function sort(array, compare) {
  if (array.length <= 1) {
    return array;
  }

  var i;
  var middle = Math.floor(array.length / 2);
  var left = new Array(middle);
  var right = new Array(array.length - middle);

  for (i = 0; i < left.length; i++) {
    left[i] = array[i];
  }
  for (i = 0; i < right.length; i++) {
    right[i] = array[i + left.length];
  }

  return merge(sort(left, compare), sort(right, compare), compare);
}
613750
function(a, b) {
        var self = this;

        function equalArrays(a, b) {
            if (a.length !== b.length) {
                return false;
            }

            var length = a.length;
            var i;
            for (i = 0; i < length; i++) {
                if (!self.equal(a[i], b[i])) {
                    return false;
                }
            }

            return true;
        }

        function equalObjects(a, b) {
            var keysA = Object.keys(a);
            var keysB = Object.keys(b);

            keysA.sort();
            keysB.sort();

            if (keysA.length !== keysB.length) {
                return false;
            }

            var length = keysA.length;
            var i;
            var key;
            for (i = 0; i < length; i++) {
                if (keysA[i] !== keysB[i]) {
                    return false;
                }

                key = keysA[i];
                if (!self.equal(a[key], b[key])) {
                    return false;
                }
            }

            return true;
        }

        var typeA = this.typeOf(a);
        var typeB = this.typeOf(b);

        if (typeA !== typeB) {
            return false;
        }

        switch (typeA) {
            case 'Null':
            case 'Boolean':
            case 'Number':
            case 'String':
            case 'Filter':
                return a === b;

            case 'RegExp':
                return a.source === b.source
                    && a.global === b.global
                    && a.multiline === b.multiline
                    && a.ignoreCase === b.ignoreCase;

            case 'Date':
            case 'Duration':
                return JuttleMoment.eq(a, b);

            case 'Array':
                return equalArrays(a, b);

            case 'Object':
                return equalObjects(a, b);
        }
    }
1171715
function _sortZ(a, b) {
         return b.pos && a.pos ? b.pos.z - a.pos.z : a.pos ? -Infinity : Infinity;
       }
617720
function neighbourhoodSorter (a, b) {
  a = a.join(',');
  b = b.join(',');
  return a > b ? 1 : a < b ? -1 : 0;
}
61447
function(arr) {
  arr = arr.sort((a, b) => {
    if (a.index > b.index) {
      return 1;
    }
    if (a.index === b.index) {
      return 0;
    }
    return -1;
  });
  //return ts objects
  return arr.map((o) => o.ts);
}
458483
function defaultCompareKeysFunction (a, b) {
  if (a < b) { return -1; }
  if (a > b) { return 1; }
  if (a === b) { return 0; }

  var err = new Error("Couldn't compare elements");
  err.a = a;
  err.b = b;
  throw err;
}
54473
function calculateDiff() {
    // we need to take 2 pointers
    // and travel progressively between them ...
    var newFirst = [
      [].concat(array1Extract[0]),
      [].concat(array1Extract[1])
    ];
    var newSecond = [
      [].concat(array2Extract[0]),
      [].concat(array2Extract[1])
    ];
    var array1Length = array1Extract[0] ? array1Extract[0].length : 0;
    var array2Length = array2Extract[0] ? array2Extract[0].length : 0;

    var pos1 = 0;
    var pos2 = 0;
    var previous2 = 0;
    while (pos1 < array1Length) {
      var diff = newFirst[0][pos1] - array2Extract[0][pos2];
      if (Math.abs(diff) < widthBottom) { // there is some overlap
        var overlap;
        if (options.trapezoid) {
          overlap = getOverlapTrapezoid(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        } else {
          overlap = getOverlap(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        }
        newFirst[1][pos1] -= overlap;
        newSecond[1][pos2] -= overlap;
        if (pos2 < (array2Length - 1)) {
          pos2++;
        } else {
          pos1++;
          pos2 = previous2;
        }
      } else {
        if (diff > 0 && pos2 < (array2Length - 1)) {
          pos2++;
          previous2 = pos2;
        } else {
          pos1++;
          pos2 = previous2;
        }
      }
    }
    return newSecond;
  }
644038
function rangesIntersect(rangeA, rangeB) {
  return rangeA.compareBoundaryPoints(Range.END_TO_START, rangeB) === -1 &&
    rangeA.compareBoundaryPoints(Range.START_TO_END, rangeB) === 1
}
159954
function sortJapanese(a, b) {
        a = normalize(a);
        b = normalize(b);
        if (a < b) {
            return -1;
        }
        if (a > b) {
            return 1;
        }
        return 0;
    }
142785
function get2(a, b, index)
{
	return index < a.length
		? a[index]
		: b[index - a.length];
}
789480
protected static double distanceSq(double[] a, double[] b) {
		double sum = 0;
		for (int i = 0; i < a.length; i++) {
			double d = a[i]-b[i];
			sum += d*d;
		}
		return sum;
	}