Switched receiver and slice order in cumsum and added check for nil receiver

This commit is contained in:
btracey
2013-05-16 14:58:23 -07:00
parent f0e1850882
commit fae9dcf298

View File

@@ -61,7 +61,10 @@ func Prod(s []float64) (prod float64) {
// Finds the cumulative sum of the first i elements in
// s and puts them in place into the ith element of the
// receiver. If the receiver is nil a new slice is created
func CumSum(s, receiver []float64) []float64 {
func CumSum(receiver, s []float64) []float64 {
if receiver == nil {
receiver = make([]float64, len(s))
}
if len(s) == 0 {
return receiver[:0]
}