mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 20:11:26 +08:00
17 lines
216 B
Go
17 lines
216 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
type IntVector []int
|
|
|
|
func (v IntVector) Sum() (s int) {
|
|
for _, x := range v {
|
|
s += x
|
|
}
|
|
return
|
|
}
|
|
|
|
func main() {
|
|
fmt.Println(IntVector{1, 2, 3}.Sum()) // Output: 6
|
|
}
|