Solution: Basic Go Data Types
Let’s solve the challenges set in the previous lesson.
We'll cover the following...
We'll cover the following...
Problem 1: Solution
Here is an example of a function in Go that takes two arrays as input and concatenates them into a new slice:
Code explanation
Lines 9–14: The
concatenate()function takes in two arrays of integers,a1anda2, and creates a new array,a3, with a length equal to the sum of the lengths ofa1anda2. The function then iterates through the elements of botha1anda2and assigns them to the corresponding positions ina3.Line 15: The
a3i array s converted to a ...