Created
July 8, 2018 12:40
-
-
Save lepoetemaudit/003723424f25f71de59189f2eb2477af to your computer and use it in GitHub Desktop.
sum in golang
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 sum(numbers []int) int { | |
if len(numbers) == 0 { | |
return 0 | |
} else { | |
return numbers[0] + sum(numbers[1:]) | |
} | |
} | |
func main() { | |
fmt.Printf("result: %d", sum([]int { 1, 2, 3, 4 })) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment