Created
December 3, 2014 17:09
-
-
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
This file contains 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 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