HJ90,
<html><meta charset="utf-8">
<span> [8-16] [24-32] [40-48] [56-64] [72-80] [88-96] </span>
<br>
<input type="number" value="18" oninput="test()" /> и
<input type="number" value="59" oninput="test()" /> пересекается с
<input id="result" disabled="true" style="width: 500px;font-size:12px; "/>
<style>
body {text-align:center}
span {display:inline-block; padding:15px; font-size:18px; font-family:consolas}
input {width:100px; height:50px; font-size:35px; text-align:center}
</style>
<script>
window.onload = test;
var intervals = [
{beg: 8, end: 16},
{beg: 24, end: 32},
{beg: 40, end: 48},
{beg: 56, end: 64},
{beg: 72, end: 80},
{beg: 88, end: 96}
];
function test(value) {
var A = +document.querySelectorAll("input")[0].value;
var B = +document.querySelectorAll("input")[1].value;
function bin_search_range(arr) {
for (;arr.length; ) {
if (arr[0].beg <= B && arr[0].end >= A) {
break;
}
arr = arr.slice(1);
}
for (var i=0; i<arr.length; i++) {
if (arr[i].beg <= B && arr[i].end >= A) continue;
else {arr = arr.slice(0,i); break;}
}
if (arr.length) {
return JSON.stringify(arr)
}
return "..."
}
document.querySelector("#result").value = bin_search_range(intervals)
};
</script>
</html>