// Code that can handle VERY large numbers by treating them as strings.
var a = {
"362439239671087109": {
"coins": 19
},
"178538363954003968": {
"coins": 18
},
"234255082345070592": {
"coins": 137
}
};
function padWithZeros(s) {
return ("000000000000000000000" + s).substr(-20);
}
var b = Object.keys(a);
b.sort(
function(x, y) {
var s1 = padWithZeros(a[x].coins);
var s2 = padWithZeros(a[y].coins);
if (s1 === s2) {
return 0;
}
if (s1 > s2) {
return 1;
} else {
return -1;
}
});
console.log(b);