postheadericon 6. Write a JavaScript to remove the highest element from the array and arrange the array in ascending order.




<html>
<head>
<title>EX-6: WTAD : www.bipinrupadiya.com</title>
<script type="text/javascript">
var a=new Array();
function addEle()
{
a.push(parseInt(document.myForm.txtEle.value));
document.getElementById("arrayEle").innerHTML=a;
document.myForm.txtEle.value="";
document.myForm.txtEle.focus();
}
function removeEle()
{

var l=a.length;
for(i=0;i<=l;i++)
{
for(j=i+1;j<l;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
document.getElementById("delEle").innerHTML="<br><br><b><font color='red'>The Highest element [ "+a.pop()+" ] is deleted</font></b><br>";
document.getElementById("sortedEle").innerHTML="<br><br><b><u>Sorted Array:</u></b><br>"+a;
}
</script>
</head>
<body>
<form name=myForm>
Enter Array Element:<input type="text" id="txtEle">
<input type="button" value="ADD" onClick="addEle();">
<input type="button" value="REMOVE" onClick="removeEle();">
</br>
</br>
<b><u>Elements In Array:</u></b>
</form>
<div id="arrayEle"></div>
<div id="delEle"></div>
<div id="sortedEle"></div>
</body>
</html>

0 comments:

Follow by Email

Blog Archive

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.