Forum : array assignment of javascript
Brief description  about Online courses   join in Online courses
View Sweety  Agarwal 's Profile

array assignment of javascript

sir,
plz help me in below query..

to make an array of size 10 and put random number in the array, make the sorting of array in ascending order.
Asked by Sweety Agarwal | Nov 8, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Sweety,

Check the below code...



rarray = new Array(10);

for(v=0 ; v<10 ; v++)
{
rarray[v] = Math.round((Math.random()*1000));
}

// use normal bubble sort function
for (i=0 ; i<10-1 ; i++)
for (j=0 ; j<10-1-i ; j++)
if (rarray[j] > rarray[j+1])
{
t = rarray[j];
rarray[j] = rarray[j+1];
rarray[j+1] = t;
}

alert(rarray.join([" : "]));
Nov 10, 2010