From bfc8293304cde8c7945239a3b5af6a8f0d559416 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Tue, 25 Jun 2024 18:40:20 +0800 Subject: [PATCH] algorithm: remove `index` from bisect --- src/algorithm/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/algorithm/index.ts b/src/algorithm/index.ts index cd30000..53f0983 100644 --- a/src/algorithm/index.ts +++ b/src/algorithm/index.ts @@ -29,22 +29,19 @@ export async function autoBisect( end: number, check: ( begin: number, - end: number, - index: number + end: number ) => Promise) { // Try to find the first index where check() predicates to true. // Assume check() is true at first, for range [begin, end) - let index = 0; while (end - begin > 1) { const mid = Math.floor((end - begin) / 2) + begin; - if (await check(begin, mid, index)) { + if (await check(begin, mid)) { // Shrink half range. end = mid; } else { begin = mid; } - index++; } return begin;