Is there a way to refactor the function below that currently uses forEach to instead use filter? I've searched online but couldn't find a suitable solution.
pendingPaymentsUtils.getPendingPayment = paymentId => {
const payments = pendingPaymentsUtils.getPendingPayments()
let payment = {}
payments.forEach(function(_payment) {
if (_payment.id === paymentId) {
payment = _payment
return false
}
})
return payment
}
I attempted the following approach, but it didn't work as intended.
pendingPaymentsUtils.getPendingPayment = paymentId => {
const payments = pendingPaymentsUtils.getPendingPayments()
let payment = {}
payments.filter(function(_payment) {
payment = _payment
return _payment.id === paymentId ? false: true
})
return payment
}