implement transaction.go:Transactions:expenses to return a new slice of only the expense transactions

main
bel 2023-10-15 12:01:35 -06:00
parent 8a469d4735
commit afa51d915e
1 changed files with 10 additions and 0 deletions

View File

@ -50,6 +50,16 @@ func (trn Transaction) isRefund() bool {
// Transactions represents a list of Transaction // Transactions represents a list of Transaction
type Transactions []Transaction type Transactions []Transaction
func (trns Transactions) expenses() Transactions {
result := make(Transactions, 0, len(trns))
for i := range trns {
if !trns[i].isRefund() {
result = append(result, trns[i])
}
}
return result
}
// Sum adds all transactions together. // Sum adds all transactions together.
func (trns Transactions) Sum() Amount { func (trns Transactions) Sum() Amount {
result := Amount(0.0) result := Amount(0.0)