Created
May 28, 2014 02:53
-
-
Save shockalotti/6a031a8b3ce77178bf3e to your computer and use it in GitHub Desktop.
Go Golang - variadic function, find greatest number in list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fails when called with only negative numbers; also when passed no args.
can address both issues by changing line
6
to be: