JSFiddle - React, Tailwind, and code Playground
by s4ty
JavaScript
var x = {
1 : {
"a" : "7"
},
10 : {
"a" : "9"
},
17 : {
"a" : "2"
}
};
var arr = [];
j = 0;
$.each(x, function (i) { arr.push(i); });
/*
while (j < arr.length) {
var temp = x[j];
x[j] = sort(x[j], x[j+1]);
x[j+1] = temp;
}
function sort(a,b) {
return (a.a < b.a) ? a : b;
}*/
console.log(x);
sort(x);
console.log(x);
function swap(z,a,b) {
temp=z[a];
z[a]=z[b];
z[b]=temp;
}
function sort(z) {
for(m=arr.length-1; m>0; m--)
for(n=0; n<m; n++) {
//console.log(x[arr[n+1]]);
if(x[arr[n+1]]) {
if (x[arr[n]].a<x[arr[n+1]].a)
swap(z,n,n+1);
}
}
}