I need some help with this algorithm, i would like to get the sorted highest prices of Venta (sell), i can sort each pair content, but i can't realize how to sort the properties order too (by the highest price of first inner). Below is the code i have for now, and my expected output. Thanks in advance.
const data = {
busd_ars: {
belo: 'Invalid pair',
binanceP2P: { Compra: 280, Venta: 278.41 },
bitso: { Compra: 283.6615, Venta: 279.4225 },
buenbit: { Compra: 285.2, Venta: 275.5 },
cryptoMkt: { Compra: 281.4251, Venta: 267.8393 }
},
dai_ars: {
belo: { Compra: 282.0846, Venta: 269.784 },
binanceP2P: { Compra: 281.45, Venta: 278.65 },
bitso: { Compra: 287.5624, Venta: 276.7951 },
buenbit: { Compra: 285.8, Venta: 274.8 },
cryptoMkt: { Compra: 279.6464, Venta: 267.7461 }
},
usdc_ars: {
belo: { Compra: 282.0846, Venta: 269.784 },
binanceP2P: 'Invalid pair',
bitso: { Compra: 283.6615, Venta: 279.4205 },
buenbit: { Compra: 285.2, Venta: 275.5 },
cryptoMkt: { Compra: 279.5047, Venta: 267.8935 }
},
usdt_ars: {
belo: { Compra: 282, Venta: 270 },
binanceP2P: { Compra: 280.49, Venta: 279.15 },
bitso: { Compra: 287.1397, Venta: 276.4963 },
buenbit: { Compra: 285.2, Venta: 275.6 },
cryptoMkt: { Compra: 279.4978, Venta: 268.0277 }
}
}
const getHighPrices = (stablesFiat) => {
const result = {}
for (let pair in stablesFiat) {
let data = {}
Object.entries(stablesFiat[pair])
.filter(x => x[1] != 'Invalid pair')
.sort((a, b) => b[1].Venta - a[1].Venta)
.slice(0, 3)
.forEach(x => {
data[x[0]] = x[1].Venta
})
result[pair] = data
}
return result
}
console.log(getHighPrices(data))
// expected output
const result = {
busd_ars: {},
usdc_ars: {},
usdt_ars: {},
dai_ars: {}
}