Solution based on binary search


#1

findCount : function(A, B){
let index = this.binary(A, B, 0, A.length-1);
let left=index, right=index;
let count=0;
while(A[left–] === B) count++;
while(A[++right] === B) count++;

 return count;
},

binary : function(a, b, low, high) {
     let mid;
    while (low <= high) {
      mid = Math.floor((low + high) / 2);
      if (a[mid] === b) return mid;
      else if (b < a[mid]) high = mid-1;
      else low = mid + 1;
    }
      return mid;
    }