I am trying to append new dayContributions to the array weekContributions.AllDays.
[Line 24] is the part appends to the AllDays property of the current type weekContributions.
[Line 47-49] is the part that calls the function. The print statement prints the weekContributions array with a single member in the array. But the following print statement [Line 51] says that all map values i.e. weekContributions objects have empty arrays as AllDays property.
My aim - To append dayContribution objects to values in map activity.yearContributions [Line 28]
I think -
The append function is working as intended as it appends 1 member on each iteration
Somehow, the currentWeekContribution.addContribution line here is only appending to the local variable currentWeekContribution and doesn’t update the corresponding value in currentActivity.yearContributions map
I am very new to golang and I think I am not following the go way / this would have worked in java or ruby
I don’t know what this behaviour is called, so can’t google search anything relevant.
Hi @vedharish, here’s my quick solution. In your func (currentActivity *Activity) restore()AllDays:make([]dayContributions, 0) it use same address of memory and it’s length is set to zero. In my solution I used pointer to allocate new address in memory in AllDays.