Javascript Array binarySearch(e, i, j)

Description

Javascript Array binarySearch(e, i, j)


'use strict'//from   w ww.  jav a 2s . c om

Array.prototype.binarySearch = function (e, i, j) {
    var m = (i + j) >> 1;
    if (e < this[m])
        return this.binarySearch(e, i, m);
    else if (e > this[m])
        return this.binarySearch(e, m, j);
    else if (e == this[m])
        return this[m];
    else
        return null;
}



PreviousNext

Related