src/SessionRecording.js
function findFrame(minIndex, maxIndex, timestamp) {

        // Do not search if the region contains only one element
        if (minIndex === maxIndex)
            return minIndex;

        // Split search region into two halves
        var midIndex = Math.floor((minIndex + maxIndex) / 2);
        var midTimestamp = toRelativeTimestamp(frames[midIndex].timestamp);

        // If timestamp is within lesser half, search again within that half
        if (timestamp < midTimestamp && midIndex > minIndex)
            return findFrame(minIndex, midIndex - 1, timestamp);

        // If timestamp is within greater half, search again within that half
        if (timestamp > midTimestamp && midIndex < maxIndex)
            return findFrame(midIndex + 1, maxIndex, timestamp);

        // Otherwise, we lucked out and found a frame with exactly the
        // desired timestamp
        return midIndex;

    }
function findFrame(minIndex, maxIndex, timestamp) {

        // Do not search if the region contains only one element
        if (minIndex === maxIndex)
            return minIndex;

        // Split search region into two halves
        var midIndex = Math.floor((minIndex + maxIndex) / 2);
        var midTimestamp = toRelativeTimestamp(frames[midIndex].timestamp);

        // If timestamp is within lesser half, search again within that half
        if (timestamp < midTimestamp && midIndex > minIndex)
            return findFrame(minIndex, midIndex - 1, timestamp);

        // If timestamp is within greater half, search again within that half
        if (timestamp > midTimestamp && midIndex < maxIndex)
            return findFrame(midIndex + 1, maxIndex, timestamp);

        // Otherwise, we lucked out and found a frame with exactly the
        // desired timestamp
        return midIndex;

    }
function findFrame ( minIndex , maxIndex , timestamp ) { // Do not search if the region contains only one element if ( minIndex === maxIndex ) return minIndex ; // Split search region into two halves var midIndex = Math . floor ( ( minIndex + maxIndex ) / 2 ) ; var midTimestamp = toRelativeTimestamp ( frames [ midIndex ] . timestamp ) ; // If timestamp is within lesser half, search again within that half if ( timestamp < midTimestamp && midIndex > minIndex ) return findFrame ( minIndex , midIndex - 1 , timestamp ) ; // If timestamp is within greater half, search again within that half if ( timestamp > midTimestamp && midIndex < maxIndex ) return findFrame ( midIndex + 1 , maxIndex , timestamp ) ; // Otherwise, we lucked out and found a frame with exactly the // desired timestamp return midIndex ; }
Searches through the given region of frames for the frame having a
relative timestamp closest to the timestamp given.

@private
@param {Number} minIndex
The index of the first frame in the region (the frame having the
smallest timestamp).

@param {Number} maxIndex
The index of the last frame in the region (the frame having the
largest timestamp).

@param {Number} timestamp
The relative timestamp to search for, where zero denotes the first
frame in the recording.

@returns {Number}
The index of the frame having a relative timestamp closest to the
given value.
Searches through the given region of frames for the frame having a relative timestamp closest to the timestamp given .