From the course: Learning Go

Unlock this course with a free trial

Join today to access over 24,200 courses taught by industry experts.

Solution: Convert a slice of strings to a map

Solution: Convert a slice of strings to a map - Go Tutorial

From the course: Learning Go

Solution: Convert a slice of strings to a map

(upbeat music) - [Instructor] In this challenge, you're given a collection of string values wrapped in a slice object. These string values should be converted to a map object. A map object is a collection of key value pairs. And in this example, the keys will be strings and the associated values will be float64s. Additionally, the challenge asks you to make sure that the total of all those associated values add up to 100. I'll test my code and show that my code got it right. I end up with a map object where each of the keys is one of the fruit strings, and the four values add up to 100. Here's how I wrote that code. I started off with a map object that was part of the starting code, and the map object is created from the make function, and I'm passing in the map signature saying that the key is a string and the associated value is a float64. Next I set a value that I'll assign to each of the items in the map, and I get…

Contents