const operations = [
{"id": 1, "timestamp": 2, "amount": 1},
{"id": 2, "timestamp": 3, "amount": 8},
{"id": 1, "timestamp": 3, "amount": 2}
]
const filter = (operations) => {
const qwerty = operations.reduce((acc, operation) => {
const cached = acc[
operation.id];
if (!cached || operation.timestamp > cached.timestamp) {
acc[
operation.id] = operation;
}
return acc;
}, {});
return Object.values(qwerty)
};
filter(operations)