SortedList.prototype.key = function()

in src/lib/sortedList.js [131:138]


SortedList.prototype.key = function(val, bsResult) {
  if (bsResult== null) bsResult = this.bsearch(val);
  var pos = bsResult;
  if (pos == -1 || this._compare(this[pos], val) < 0)
    return (pos+1 < this.length && this._compare(this[pos+1], val) == 0) ? pos+1 : null;
  while (pos >= 1 && this._compare(this[pos-1], val) == 0) pos--;
  return pos;
};