Solution: Introduction to Go

Let’s solve the challenges set in the previous lesson.

Problem 1: Solution

To find all possible occurrences of the desired executable, we can make the following changes to the which.go code:

  1. Declare a results variable of type []string to store all the full paths of the executable.

  2. Inside the for loop, after finding an executable, instead of returning immediately, append the full path of the executable to the results variable.

  3. After the first for loop, use another for loop to iterate over the results variable and print all the full paths.

  4. Remove the return statement at the end of the for loop.

Here is an example of the updated code:

Get hands-on with 1400+ tech skills courses.