Skip to content

Instantly share code, notes, and snippets.

@YAAK
Created December 3, 2014 17:09
Show Gist options
  • Save YAAK/85436ab31f2be689d704 to your computer and use it in GitHub Desktop.
Save YAAK/85436ab31f2be689d704 to your computer and use it in GitHub Desktop.
A simple function written in Go, to find the biggest integer in an integer slice using a recursive approach
package main
import "fmt"
func max(arr []int) (m int) {
if len(arr) > 2 {
m = max( []int{ arr[0], max(arr[1:])} )
} else {
m = (map[bool]int{true : arr[0], false : arr[1]})[ arr[0] >= arr[1] ]
}
return
}
func main() {
var s []int;
s = make([]int, 10)
s[0] = 1
s[3] = 15
s[9] = 8
fmt.Println(max(s))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment