Skip to content

Instantly share code, notes, and snippets.

@shockalotti
Created May 28, 2014 02:02
Show Gist options
  • Save shockalotti/d01ab9540c32458f0703 to your computer and use it in GitHub Desktop.
Save shockalotti/d01ab9540c32458f0703 to your computer and use it in GitHub Desktop.
Go Golang - slice sum function
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))
}
@jhlr
Copy link

jhlr commented Apr 10, 2016

This package allows the sorting of any slice:
https://github.com/jhlr/slices

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment