dc65k,
<script>
/*
input:
[
[9, 10],
[15, 17],
[14, 16],
]
output:
[
[10, 14],
[17, 18],
]
*/
const input = [
[9, 10],
[15, 17],
[14, 16]
];
const getWorkTime = (input, min, max) => {
let ar = [], temp = [], push;
for (let i = min; i <= max; i++) {
let clear = input.some(([a, b]) => i >= a && i < b);
let len = temp.length;
if (clear) {
if (len) {
temp[1] = i;
temp = [];
push = false;
}
} else temp[+!!len] = i;
if (temp.length == 2 && !push) {
ar.push(temp);
push = true;
}
}
return ar
}
let a = getWorkTime(input, 9, 18);
document.write(JSON.stringify(a))
</script>