-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
27 lines (23 loc) · 953 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const arrs = [
{ tb_trade_id: 1, tk_refund_time: '2024-06-23 18:20:25' },
{ tb_trade_id: 1, tk_refund_time: '2024-06-23 18:21:25' },
{ tb_trade_id: 2, tk_refund_time: '2024-06-23 18:20:25' },
{ tb_trade_id: 2, tk_refund_time: '2024-06-23 18:22:25' },
{ tb_trade_id: 3, tk_refund_time: '2024-06-23 18:20:25' },
{ tb_trade_id: 3, tk_refund_time: '2024-06-23 18:22:25' },
{ tb_trade_id: 4, tk_refund_time: '2024-06-23 18:20:25' },
{ tb_trade_id: 5, tk_refund_time: '2024-06-23 18:20:25' },
];
const removeDuplicates = (data) => {
const uniqueData = {};
data.forEach((item) => {
const tbTradeId = item.tb_trade_id;
const tkRefundTime = new Date(item.tk_refund_time);
if (!uniqueData[tbTradeId] || tkRefundTime > new Date(uniqueData[tbTradeId].tk_refund_time)) {
uniqueData[tbTradeId] = item;
}
});
return Object.values(uniqueData);
};
const filteredData = removeDuplicates(arrs);
console.log(filteredData);