programming-examples/js/Array/Write a JavaScript program to sort the items of an array..js

28 lines
663 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
var arr1=[-3,8,7,6,5,-4,3,2,1];
var arr2=[];
var min=arr1[0];
var pos;
max=arr1[0];
for (i=0; i<arr1.length; i++)
{
if (max<arr1[i]) max=arr1[i];
}
for (var i=0;i<arr1.length;i++)
{
for (var j=0;j<arr1.length;j++)
{
if (arr1[j]!="x")
{
if (min>arr1[j])
{
min=arr1[j];
pos=j;
}
}
}
arr2[i]=min;
arr1[pos]="x";
min=max;
}
console.log(arr2);