functiong of array sort

Solutions on MaxInterview for functiong of array sort by the best coders in the world

showing results for - "functiong of array sort"
Amy
15 Sep 2016
1let arr = [90, 1, 20, 14, 3, 55];
2var sortRes = [];
3var copy = arr.slice();		//create duplicate array
4var inc = 0;	//inc meant increment
5copy.sort((a, b) => {
6	sortRes[inc] = [ a, b, a-b ];
7	inc += 1;
8	return a - b;
9});
10var p = 0;
11for (var i = 0; i < inc; i++) {
12	copy = arr.slice();
13	copy.sort((a, b) => {
14		p += 1;
15		if (p <= i ) {
16			return a - b;
17		}
18		else{
19			return false;
20		}
21	});
22	p = 0;
23	console.log(copy +' \t a: '+ sortRes[i][0] +' \tb: '+ sortRes[i][1] +'\tTotal: '+ sortRes[i][2]);
24}
similar questions
queries leading to this page
functiong of array sort