جستجو دودویی در JavaScript براتون اماده کردم امید وارم ازش استفاده کنید و کمکی بهتون کنه....موفق باشید

 <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="javascript" type="text/javascript">
function bs(myform)
{

var i = 0;
var test = myform.txtnum.value;
var test2size = 0;
var object=eval(myform.search_obj.value)

//start incoding char Array test to int Array test2. (example:5,3,1,2,6,4,2,(char) to 5,3,1,2,6,4,2(int))
for (i = 0; i < myform.txtnum.value.length; i++)
{

if (test.charAt(i) == ',')
{
test2size++;
}

}

var test2 = new Array(test2size);
test2size = 0;
test2[test2size]=0;
for (i = 0; i < myform.txtnum.value.length; i++)
{

if (test.charAt(i) != ',')
{

test2[test2size] = ((test2[test2size] * 10) + parseInt(test.charAt(i)));
}
else
{
test2size++;
test2[test2size]=0;
}
}
//end incoding


//Sorting Array by Buble Algorithm
var temp = 0;
for (i = test2size - 1; i > 0; i--)
{
for (j = 0; j < i; j++)
{
if (test2[j] > test2[j + 1])
{
temp = test2[j];
test2[j] = test2[j + 1];
test2[j + 1] = temp;
}
}
}
//شروع دستورات جست و جو

//Search object in test2 array
var first = 0;
var last = test2size - 1;
var middle = Math.floor((first + last) / 2);

while(last >= first)
{
if(test2[middle] == object)
{
alert("Find Your Number In Element "+(middle+1)+" .")
return ;
}
else if(test2[middle] > object)
{
last = middle-1;
middle = Math.floor((first + last) / 2);
}else
{
first = middle+1;
middle = Math.floor((first + last) / 2);
}
}
alert("Not Find :(")
}
</script>
<body>
<form name="form1">
Enter number's (Array for Example:"5,6,3,4,2,3,".without "" and Any Space):<br><input type="text" name="txtnum"><br>
Enter Number to search below.<br>
<input type="text" name="search_obj">
<input type="button" value=" Binary Search " onClick="bs(form1)">
</form>
</body>
</html>