Skip to content

Commit

Permalink
fix: getNearestVals util
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Feb 19, 2024
1 parent c0512dc commit bde25ae
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/zoom_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,16 @@ const getNearestVals = <T>(arr: T[], target: T): [T, T] => {
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) {
right = mid === 0 ? 0 : mid - 1;
left = mid === arr.length - 1 ? arr.length - 1 : mid + 1;
right = mid - 1;
left = mid + 1;
break;
} else if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
if (right < 0) right = 0;
if (left >= arr.length) left = arr.length - 1;
return [arr[right], arr[left]];
};

0 comments on commit bde25ae

Please sign in to comment.