Skip to content

Commit

Permalink
Dynamically grow the data slice
Browse files Browse the repository at this point in the history
  • Loading branch information
HelixSpiral committed Feb 28, 2018
1 parent b8545a6 commit 8c0fad1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions csvreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func readData(powerFile string) [][]PowerData {
panic(err)
}

data := make([][]PowerData, len(lines))
data := make([][]PowerData, 1)
var previousDay time.Time
var currentDay time.Time
var dayCount int
Expand All @@ -39,8 +39,8 @@ func readData(powerFile string) [][]PowerData {
kWh: kilowatt,
})
} else {
data = append(data, nil)
dayCount += 1
data[dayCount] = make([]PowerData, 0)
data[dayCount] = append(data[dayCount], PowerData{
date: currentDay,
kWh: kilowatt,
Expand Down

0 comments on commit 8c0fad1

Please sign in to comment.