Created
May 28, 2014 02:02
-
-
Save shockalotti/d01ab9540c32458f0703 to your computer and use it in GitHub Desktop.
Go Golang - slice sum function
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 sumSlices(x[]float64, y[]float64) float64 { | |
totalx := 0.0 | |
for _, valuex := range x { | |
totalx += valuex | |
} | |
totaly := 0.0 | |
for _, valuey := range y { | |
totaly += valuey | |
} | |
return totalx + totaly | |
} | |
func main() { | |
x := []float64{1,2,3,4,5} | |
y := []float64{11,12,13,14,15} | |
fmt.Println(sumSlices(x, y)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This package allows the sorting of any slice:
https://github.com/jhlr/slices