[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-06 Thread timilsina . ashish . 03
Awesome, that makes so much sense. Thanks for explaining it and your help! On Monday, March 5, 2018 at 4:03:33 PM UTC-7, Ignacio Gómez wrote: > > Hi, Ashish. > > If you have a map[string]int (or int 64, float 64, etc.) "m", doing > > m[key] += value > > > is equivalent to this: > > m[key] = m[key]

[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread Ignacio Gómez
Hi, Ashish. If you have a map[string]int (or int 64, float 64, etc.) "m", doing m[key] += value is equivalent to this: m[key] = m[key] + value. Thus, on each iteration we sum the value at dataarray[j][1] (which you stored at sumFloat) to the current value of sums[dataarray[j][0]] (on first

[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread timilsina . ashish . 03
Hi Ignacio, This is excellent, works perfectly. Thank you so much. I will try to do my research but just out of curiosity and make sure I understand the code, what does this line do? I also don't have proper understanding of golang maps sums[dataarray[j][0]] += sumFloat So 'sum' map is takin

[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread Ignacio Gómez
You can use a map to keep track of a letters sum. Here's your example slightly modified (it uses float64 as you were using that): https://play.golang.org/p/98L9fDXSN_A El lunes, 5 de marzo de 2018, 15:28:54 (UTC-3), Ashish Timilsina escribió: > > Hi, > > I have an array of array string ([][]stri