mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
estlop
2c324911d5
|
2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago |
README.md
multorsum
Instructions
Write a function that receives a slice of int and an int representing the initial value. If the int is odd it should multiply the accumulated value. If it is even, it should be added instead. Return the result. If the slice is empty return 0.
Expected function
func MultOrSum(ints []int, init int) int {
}
Usage
Here is a possible program to test your function :
package main
func main() {
fmt.Println(MultOrSum([]int{1, 2, 3, 4}, 3 ))
fmt.Println(MultOrSum([]int{1, 2, 3, 4}, 0 ))
fmt.Println(MultOrSum([]int{1, -2, 3, 4}, 0 ))
}
And its output :
$ go run . | cat -e
19$
10$
-2$