#go: lasagna master

5 messages · Page 1 of 1 (latest)

latent hinge
#

package lasagna

// TODO: define the 'PreparationTime()' function
func PreparationTime(layers []string, avg_prep_time int) int {

if (avg_prep_time == 0 ) {
    avg_prep_time = 2;
}
ret := (len(layers) * avg_prep_time); 

return ret;

}
// TODO: define the 'Quantities()' function
func Quantities(layers []string) (int, float64) {
noodles := 0;
sauce := 0.0;
for i := 0 ; i < len(layers); i++ {
switch layers[i] {
case "noodles" : noodles += 50;
case "sauce" : sauce += 0.2
}
}

return noodles, sauce;

}
// TODO: define the 'AddSecretIngredient()' function
// AddSecretIngredient copies the last element from 'theirs' slice and appends it to the 'own' slice.
func AddSecretIngredient(theirs []string, own *[]string) {

*own = append(*own,theirs[len(theirs)-1]);      

}

// TODO: define the 'ScaleRecipe()' function
func ScaleRecipe(quantities []float64, portions int) []float64 {
scaledQuantities := make([]float64, len(quantities))
for i, quantity := range quantities {
scaledQuantities[i] = quantity * float64(portions) / 2.0
}
return scaledQuantities
}

// Your first steps could be to read through the tasks, and create
// these functions with their correct parameter lists and return types.
// The function body only needs to contain panic("").
//
// This will make the tests compile, but they will fail.
// You can then implement the function logic one by one and see
// an increasing number of tests passing as you implement more
// functionality

Add Secret Ingredient doesnt go through test. What's the problem?

#

doesn't work

winged locust
#

The type parameters for the function are slightly wrong. Start with fixing that. The instructions for the exercise provide an example on how the function will be used - pay attention to the types of the arguments being passed in and their types. With that you can infer the type of the parameters your function should take.

distant vigilBOT
rapid pecan
#

Hello, can someone please assist me on how to go about Guidos Lasagna, I have tried but still getting errors