-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank_txn.go
44 lines (35 loc) · 929 Bytes
/
bank_txn.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"strings"
"github.com/shopspring/decimal"
)
type bankTxn struct {
description string
amount decimal.Decimal
}
func newBankTxn(description, amount string) (*bankTxn, error) {
amt, err := decimal.NewFromString(amount)
if err != nil {
return nil, err
}
return &bankTxn{strings.ToUpper(strings.TrimSpace(description)), amt}, nil
}
func (t1 *bankTxn) equal(t2 *bankTxn) bool {
return t1.description == t2.description && t1.amount.Equal(t2.amount)
}
func filterInterestingTxns(source []*bankTxn, interestingAmounts []decimal.Decimal) (interestedTxns []*bankTxn, junkTxns []*bankTxn) {
for _, txn := range source {
found := false
for _, amount := range interestingAmounts {
if amount.Equal(txn.amount) {
interestedTxns = append(interestedTxns, txn)
found = true
break
}
}
if !found {
junkTxns = append(junkTxns, txn)
}
}
return interestedTxns, junkTxns
}