refactor: fit user message in screen

This commit is contained in:
Carlos Valente
2024-09-18 22:13:49 +02:00
committed by Carlos Valente
parent 66083813f9
commit bc6b7c5596
5 changed files with 95 additions and 20 deletions
@@ -0,0 +1,18 @@
/**
* @param low inclusive, must be true on predicate function
* @param high exclusive,
* @param predicate predicate function
*/
export const bsearch = (low: number, high: number, predicate: (mid: number) => boolean): number => {
while (low < high) {
const mid = Math.floor((low + high) / 2);
if (mid === low) break;
if (predicate(mid)) {
low = mid;
} else {
high = mid;
}
}
return low;
};