0
0
0
share
#devhandal#alibabacloud
0 Komentar
sort dan filter in Javascript
saya punya code seperti ini : const transactions = [ { id: 1, amount: 200, type: "credit", date: "2023-01-01", description: "Payment received" }, { id: 2, amount: 150, type: "debit", date: "2023-01-02", description: "Purchase at store" }, { id: 3, amount: 300, type: "credit", date: "2023-01-03", description: "Payment received" }, { id: 4, amount: 50, type: "debit", date: "2023-01-04", description: "Purchase online" }, { id: 5, amount: 100, type: "credit", date: "2023-01-05", description: "Payment received" }, { id: 6, amount: 400, type: "debit", date: "2023-01-06", description: "Purchase at store" }, ];
const [ {id : firstTransactionId, amount : firstTransactionAmount }, {type : secondTransactionType, description : secondTransactionDescription}
] = transactions;
const selectedTransactions = [...transactions.slice(3,5)];
const sortedCredits = transactions.filter(transaction => transaction.type === "credit").sort((a,b) => b.amount - a.amount)
nah yg membuat saya bingung itu, kenapa harus b.amount dulu di proses sorting nya ?? kenapa ga harus a.amount dulu ??
mohon jawaban nya para suhu2 🙏🙏
0
0
0
share