Nodejs Utililty Methods Array Search Binary

List of utility methods to do Array Search Binary

Description

The list of methods to do Array Search Binary are organized into topic(s).

Method

binarySearchbinaryIndexOf;
function binaryIndexOf(searchElement) {
    'use strict';
    var minIndex = 0;
    var maxIndex = this.length - 1;
    var currentIndex = -1;
    var currentElement;
    while (minIndex <= maxIndex) {
        currentIndex = (minIndex + maxIndex) / 2 | 0;
        currentElement = this[currentIndex];
...
binarySearchbinarySearch(val, from, to)
Array.prototype.binarySearch = function binarySearch(val, from, to){
    if (from === undefined) {
        from = 0;
    if (to === undefined) {
        to = this.length-1;
    var mid = Math.ceil((from+to)/2),
        midVal = this[mid];
...
binary_search(val, left, right)
Array.prototype.binary_search = function(val, left, right) {
    if (typeof left === 'undefined') left = 0;
    if (typeof right === 'undefined') right = this.length - 1;
    if (left > right) return null;
    var mid = (left + right) >> 1;
    if (val == this[mid]) {
        return mid;
    } else if (val > this[mid]) {
        return this.binary_search(val, mid + 1, right);
...
binarysearch(i)
Array.prototype.binarysearch = function (i) {
    var l = 0, u = this.length,  m;
    while ( l <= u ) {
        m = ((l+u) >> 1);
        if ( i > this[m].i ) {
            l = m+1;
        } else {
            u = (i == this[m]) ? -2 : m - 1;
    return (u == -2) ? m : -1;
};
bsearch(target)
Array.prototype.bsearch = function (target) {
  var half = parseInt(this.length / 2);
  if (target === this[half]) {
    return half;
  if (target > this[half]) {
    return half + this.slice(half,this.length).bsearch(target);
  } else {
    return this.slice(0, half).bsearch(target);
...