Go for JavaScript Developers

# Complex Structures Exercise

Check out a free preview of the full Go for JavaScript Developers course:
The "Complex Structures Exercise" Lesson is part of the full, Go for JavaScript Developers course featured in this preview video. Here's what you'd learn in this lesson:

## Students are instructed to practice working with arrays, slices and maps by completing the different parts of the complex structures exercise.

Get Unlimited Access Now

Transcript from the "Complex Structures Exercise" Lesson

[00:00:00]
>> Okay, so for exercise foresee and, we're gonna practice some of the stuff we talked about around functions, arrays, slices and maps. And so in the foresee exercise file in section four for complex structures, the goals are going to be kind of to work with some of these structures we've just discussed.

[00:00:15] And will use range a little bit as well. So I'm going to create an exercise foresee.go file, and in part one, we're gonna kinda of review a function that we just saw recently, which is iterating over an array. The practice element here is to kinda of pass an array specifically to a function.

[00:00:32] So, on part one, number one, we're going to instantiate an array of scores, and the array of scores should have at least five elements of type float 64 and then write a function that calculates and returns that average score. The kicker here is that you should have a separate function that accepts an array as a type and then iterates over it and returns that average score.

[00:00:52] In part part two, we're gonna look at maps. So for part one of part two, let's define a map that contains a set of pet names and their corresponding animal type. For example, if you were looking at the name Fido, it would correspond it to a pet of dog.

[00:01:06] So you can have a few of these like four or five different pets within a map. And then the second part of this is to write a function that's going to take a string argument and return a Boolean indicating whether or not that key exists in your map of pets.

[00:01:20] So the structure here would be whatever is in your main function should call a second function that's like, hey, do you exist in this map, and then that string that you pass a second function, we'll go check out that map and return true or false if that key exists.

[00:01:34] And then for part three, we're gonna instantiate a slice that has an initial value of a collection of groceries, and then write a second function that takes one or more groceries as a string argument and appends them to the slice, printing out the resulting list of groceries.