(pred, from, to)
| 298 | // `pred` and is closest to `from`. Assumes that at least `to` |
| 299 | // satisfies `pred`. Supports `from` being greater than `to`. |
| 300 | function findFirst(pred, from, to) { |
| 301 | // At any point we are certain `to` satisfies `pred`, don't know |
| 302 | // whether `from` does. |
| 303 | var dir = from > to ? -1 : 1; |
| 304 | for (;;) { |
| 305 | if (from == to) { return from } |
| 306 | var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF); |
| 307 | if (mid == from) { return pred(mid) ? from : to } |
| 308 | if (pred(mid)) { to = mid; } |
| 309 | else { from = mid + dir; } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | // BIDI HELPERS |
| 314 |
no outgoing calls
no test coverage detected