Open this example in the interactive library
Source code
const busy = [
[9, 10],
[11, 13],
];
console.log(
Array.from({ length: 8 }, (_, i) => i + 9).find((t) =>
busy.every(([a, b]) => t + 1 <= a || t >= b),
),
);
Sample output
10

Open this example in the interactive library
const busy = [
[9, 10],
[11, 13],
];
console.log(
Array.from({ length: 8 }, (_, i) => i + 9).find((t) =>
busy.every(([a, b]) => t + 1 <= a || t >= b),
),
);
10