CopyCode The Code is as follows: <HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<SCRIPT type = "text/JavaScript">
// Window. Alert (math. Floor (5.7); // rounded down to output 5
// The binary search array must be ordered.
Function binaryseach (ARR, findval, leftindex, rightindex ){
// Find the Intermediate Value
VaR midindex = math. Floor (leftindex + rightindex)/2 );
VaR midval = arr [midindex];
// Prevent infinite Recursion
If (leftindex> rightindex ){
// The description cannot be found.
Document. writeln ("not found ");
Return;
}
// Search
If (midval> findval ){
// Find on the left
Binaryseach (ARR, findval, leftindex, midIndex-1 );
} Else if (midval <findval ){
// Find the description on the right
Binaryseach (ARR, findval, midindex + 1, rightindex );
} Else {
// Output or return is found
Document. writeln ("found, Subscript:" + midindex );
Return;
}
}
VaR arr = [1, 3, 12, 21, 24, 44, 54,67];
Binaryseach (ARR, 67,0, arr. Length-1 );
</SCRIPT>
</Head>
<Body> </body>
</Html>