/** * @param a A list of items * @param b An item to search its index inside the list of items */ function binarySearch(a, b) { for (var c = 0, d = a.length, e; c <= d;) { e = ~~((d + c) / 2); if (a[e] === b) return e; a[e] > b ? d = e - 1 : c = e + 1 } return -1; }