stats
stats copied to clipboard
bug report: miss makezero in slice init
I was running github actions to run linter makezero for top github golang repos.
see issues https://github.com/alingse/go-linter-runner/issues/1
and the github actions output https://github.com/alingse/go-linter-runner/actions/runs/9243004504/job/25426564828
====================================================================================================
append to slice `mode` with non-zero initialized length at https://github.com/montanaflynn/stats/blob/master/mode.go#L23:11
append to slice `mode` with non-zero initialized length at https://github.com/montanaflynn/stats/blob/master/mode.go#L34:[10](https://github.com/alingse/go-linter-runner/actions/runs/9243004504/job/25426564828#step:4:11)
====================================================================================================
https://github.com/montanaflynn/stats/blob/master/mode.go#L16C1-L23
mode = make([]float64, 5)
cnt, maxCnt := 1, 1
for i := 1; i < l; i++ {
switch {
case c[i] == c[i-1]:
cnt++
case cnt == maxCnt && maxCnt != 1:
mode = append(mode, c[i-1])
maybe the mode = make([]float64, 5)
should be mode = make([]float64, 0, 5)