implement transaction.go:Transactions:expenses to return a new slice of only the expense transactions
parent
8a469d4735
commit
afa51d915e
|
|
@ -50,6 +50,16 @@ func (trn Transaction) isRefund() bool {
|
|||
// Transactions represents a list of 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.
|
||||
func (trns Transactions) Sum() Amount {
|
||||
result := Amount(0.0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue