binaryFindIndex
let findTimes = 0;
const arr = [
{ id: 1, text: '1' },
{ id: 2, text: '2' },
{ id: 3, text: '3' },
{ id: 4, text: '4' },
{ id: 5, text: '5' },
{ id: 6, text: '6' },
];
binaryFind(arr, (o) => (findTimes++, 3 - o.item.id)); // { id: 3, text: '3' }
findTimes; // 查找遍历次数:3
findTimes = 0;
binaryFind(arr, (o) => (findTimes++, 2 - o.item.id)); // { id: 2, text: '2' }
findTimes; // 查找遍历次数:2
findTimes = 0;
binaryFind(arr, (o) => (findTimes++, 6 - o.item.id)); // { id: 6, text: '6' }
findTimes; // 查找遍历次数:2
findTimes = 0;
binaryFind(arr, (o) => (findTimes++, 7 - o.item.id)); // null
findTimes; // 查找遍历次数:2
二分查找item