Answers for "sort array of arrays"

0

functiong of array sort

let arr = [90, 1, 20, 14, 3, 55];
var sortRes = [];
var copy = arr.slice();		//create duplicate array
var inc = 0;	//inc meant increment
copy.sort((a, b) => {
	sortRes[inc] = [ a, b, a-b ];
	inc += 1;
	return a - b;
});
var p = 0;
for (var i = 0; i < inc; i++) {
	copy = arr.slice();
	copy.sort((a, b) => {
		p += 1;
		if (p <= i ) {
			return a - b;
		}
		else{
			return false;
		}
	});
	p = 0;
	console.log(copy +' t a: '+ sortRes[i][0] +' tb: '+ sortRes[i][1] +'tTotal: '+ sortRes[i][2]);
}
Posted by: Guest on June-29-2021
0

how to sort an array

var carBrands = ["Toyota", "Jeep", "Ford", "Volvo"];
carBrands.sort();
// array.sort() method sorts an array in ascending order by default
// extend the function like below to sort in descending order or customize
//carBrands.sort(function(a, b){return b-a});
Posted by: Guest on May-27-2021
-3

how to sort array

array sorting
Posted by: Guest on February-28-2021
-3

how to sort array

public static void main(String args[])
{
    int [] array = new int[10];

    array[0] = ((int)(Math.random()*100+1));
    array[1] = ((int)(Math.random()*100+1));
    array[2] = ((int)(Math.random()*100+1));
    array[3] = ((int)(Math.random()*100+1));
    array[4] = ((int)(Math.random()*100+1));
    array[5] = ((int)(Math.random()*100+1));
    array[6] = ((int)(Math.random()*100+1));
    array[7] = ((int)(Math.random()*100+1));
    array[8] = ((int)(Math.random()*100+1));
    array[9] = ((int)(Math.random()*100+1));

    System.out.println(array[0] +" " + array[1] +" " + array[2] +" " + array[3]
    +" " + array[4] +" " + array[5]+" " + array[6]+" " + array[7]+" " 
    + array[8]+" " + array[9] );        

}
Posted by: Guest on January-24-2021

Browse Popular Code Answers by Language