From 82ac6cd676e550700a525737077de04ff1936b6a Mon Sep 17 00:00:00 2001 From: jrosendo Date: Tue, 8 Nov 2022 18:10:07 +0000 Subject: [PATCH] docs(multorsum): fix subject - subject was confusing and not concise --- subjects/multorsum/README.md | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/subjects/multorsum/README.md b/subjects/multorsum/README.md index 128471c0f..cbd2cab48 100644 --- a/subjects/multorsum/README.md +++ b/subjects/multorsum/README.md @@ -2,30 +2,44 @@ ### 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. +Write a function that receives a slice of `int` and an `int` representing the initial value as arguments. + +You should traverse the slice and for each `int` check the following restrictions: + +- If the `int` is odd, multiply it by the init value. Return the accumulated value after traversing the entire slice. +- If the `int` is even, add it to the init value. Return the accumulated value after traversing the entire slice. +- If the slice is empty return `0`. ### Expected function ```go func MultOrSum(ints []int, init int) int { + } ``` ### Usage -Here is a possible program to test your function : +Here is a possible program to test your function: ```go package main +import ( + "fmt" + + "piscine" +) + 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 )) + fmt.Println(piscine.MultOrSum([]int{1, 2, 3, 4}, 3)) + fmt.Println(piscine.MultOrSum([]int{1, 2, 3, 4}, 0)) + fmt.Println(piscine.MultOrSum([]int{1, -2, 3, 4}, 0)) } + ``` -And its output : +And its output: ```console $ go run . | cat -e