server/api/helper_functions.js
// return the index of the message that is sent before a certain time, using binary search
return the index of the message that is sent before a certain time, using binary search
return the index of the message that is sent before a certain time using binary search
function indexOfMessageBefore(arr, time) {
    'use strict';
    var minIndex = 0;
    var maxIndex = arr.length - 1;
    var currentIndex;
    var currentElement;
    while (minIndex <= maxIndex) {
        currentIndex = (minIndex + maxIndex) / 2 | 0;
        currentElement = arr[currentIndex];
        if (currentElement.sent < time) minIndex = currentIndex + 1;
        else if (currentElement.sent > time) maxIndex = currentIndex - 1;
        else return currentIndex;
    }
    return currentIndex;
}
function indexOfMessageBefore ( arr , time ) { 'use strict' ; var minIndex = 0 ; var maxIndex = arr . length - 1 ; var currentIndex ; var currentElement ; while ( minIndex <= maxIndex ) { currentIndex = ( minIndex + maxIndex ) / 2 | 0 ; currentElement = arr [ currentIndex ] ; if ( currentElement . sent < time ) minIndex = currentIndex + 1 ; else if ( currentElement . sent > time ) maxIndex = currentIndex - 1 ; else return currentIndex ; } return currentIndex ; }
return the index of the message that is sent before a certain time, using binary search
return the index of the message that is sent before a certain time using binary search