<!--
//Javascript code for placing the Array values series in Randomly
function randno()
{
return (Math.floor(Math.random() * 100));
}
function sortMultiDimensional(a,b)
{
// this sorts the array using the second element
return ((a[1] < b[1]) ? -1 : ((a[1] > b[1]) ? 1 : 0));
}
function randomArrayset(inputValue){
//input Array value
//var inputValue=[0,1,2,3,4,5];
// dynamic 2 dimension array creation
var randomSeries=new Array();
for (i=0; i <inputValue.length; i++)
randomSeries[i]=new Array(1);
for (j=0; j <inputValue.length; j++)
{
//storing the input array values
randomSeries[j][0]=inputValue[j];
//storing the Random values
randomSeries[j][1]=randno();
}
randomSeries.sort(sortMultiDimensional); // sort using our custom function
for (j=0; j <inputValue.length; j++)
{
//storing random sorted to an array
inputValue[j]=randomSeries[j][0];
}
return (inputValue);
}
//intialise the Array to input
var myValue=[0,1,2,3,4,5];
document.write(randomArrayset(myValue));
//-->
</SCRIPT>
No comments:
Post a Comment