Looking to organize the data fetched from the API based on time? Take a peek at one of the objects in the array below:
{
"orderId": "xxxxxxxxxxxxx",
"amount": 10,
"status": "CREATED",
"transactionTime": 1651498914,
"type": "ADD",
"mode": "UPI",
"bankAccountId": {
"bankAccountNumber": "xxxxxxxxxxxxx",
"ifsc": "XXXX XXXX XXXX"
}
}
Want to sort the array in descending order by transactionTime, which is in epoch format?
Here's an initial approach:
data.map((item) => item.transactionTime)
.sort()
.reverse()
.map((item) => {
return data.find((i) => i.transactionTime == item);
})
Although the current code works, it might not be the most efficient method. Consider exploring a more optimized solution, like using a priority queue as suggested by some.