let n = 5,
bad = 4;
let i = 0,
j = n;
let index = 0
while (i <= j) {
index++
const o = Math.floor((j + i) / 2)
if (o < bad) {
i = o + 1
} else if (o === bad) {
console.log(index + 1);
break
} else {
j = o - 1
}
}
09-10
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-19
956
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)