While examining a TypeScript function designed to calculate average run time, I stumbled upon some unfamiliar syntax:
func averageRuntimeInSeconds(runs []Run) float64 {
var totalTime int
var failedRuns int
for _, run := range runs {
if run.Failed {
failedRuns++
} else {
totalTime += run.Time
}
}
averageRuntime := float64(totalTime) / float64(len(runs) - failedRuns) / 1000
return averageRuntime
}
I'm curious about the significance of the
:=
symbol used on the 4th line. Furthermore, the syntax for the for loop in that same line appears unconventional without parentheses. What type of for loop is being implemented here?
Lastly, can someone explain what role the range keyword plays in this context?