added average variadic to set
This commit is contained in:
parent
66f06e8dd9
commit
805c0a7e21
16
playground/averageVariadic.go
Normal file
16
playground/averageVariadic.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func average(numbers ...float64) float64 {
|
||||
var sum float64 = 0
|
||||
for _, number := range numbers {
|
||||
sum += number
|
||||
}
|
||||
return sum / float64(len(numbers))
|
||||
}
|
||||
|
||||
func averageVariadic() {
|
||||
fmt.Println(average(100, 50))
|
||||
fmt.Println(average(90.7, 89.7, 98.5, 92.3))
|
||||
}
|
@ -32,8 +32,12 @@ func main() {
|
||||
averageMySolution()
|
||||
case "Get the Average Head First Solution":
|
||||
averageHeadFirstSolution()
|
||||
case "Get the Average Variadic":
|
||||
averageVariadic()
|
||||
case "Slices":
|
||||
slices()
|
||||
case "Variadic Functions":
|
||||
variadic()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@ -48,7 +52,9 @@ func main() {
|
||||
menu.Option("Convert To Celsius", nil, false, nil)
|
||||
menu.Option("Get the Average My Solution", nil, false, nil)
|
||||
menu.Option("Get the Average Head First Solution", nil, false, nil)
|
||||
menu.Option("Get the Average Variadic", nil, false, nil)
|
||||
menu.Option("Slices", nil, false, nil)
|
||||
menu.Option("Variadic Functions", nil, false, nil)
|
||||
err := menu.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
Loading…
Reference in New Issue
Block a user