I have 3 struct data (GOLANG) that I call A, B, and C, struct C is result array replace between struct A and B when data is similar or more than 0 then I set all result to struct C using array.
Struct A, B, C {
TransactionDate string
TotalAmount string
TotalTransaction string
}
A = [
{2019-02-01 0 0}
{2019-02-02 0 0}
{2019-02-03 0 0}
{2019-02-04 0 0}
{2019-02-05 0 0}
{2019-02-06 0 0}
{2019-02-07 0 0}
]
B = [
{2019-02-02 1000 2}
{2019-02-07 200 3}
]
I expect the result is like
C = [
{2019-02-01 0 0}
{2019-02-02 1000 2}
{2019-02-03 0 0}
{2019-02-04 0 0}
{2019-02-05 0 0}
{2019-02-06 0 0}
{2019-02-07 200 3}
]
I try using like this but I can't still like my expected result, can you help me to solve this?
func compareReplace() []C{
var a []A
var b []B
var c []C
for i := 0; i < len(a); i++ {
if a[i].TransactionDate == b[i].TransactionDate {
if b[i].TotalTransaction != "0" {
c = append(c, b[i])
}
}
}
return c
}
Or we can collaborate at https://play.golang.org/p/H-aaolvSDZt