Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shockalotti/6a031a8b3ce77178bf3e to your computer and use it in GitHub Desktop.
Save shockalotti/6a031a8b3ce77178bf3e to your computer and use it in GitHub Desktop.
Go Golang - variadic function, find greatest number in list
package main
import "fmt"
func greatestNumber(args ... int) int {
max := int(0)
for _, arg := range args {
if arg > max {
max = arg
}
}
return max
}
func main() {
fmt.Println(greatestNumber(12,3,84,32,52,97,6))
}
@rck109d
Copy link

rck109d commented Mar 26, 2016

fails when called with only negative numbers; also when passed no args.
can address both issues by changing line 6 to be:

max := args[0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment