Solution Review: Magnify a Slice
This lesson discusses the solution to the challenge given in the previous lesson.
We'll cover the following...
Press + to interact
package mainimport "fmt"var s []intfunc main() {s = []int{1, 2, 3}fmt.Println("The length of s before enlarging is:", len(s))fmt.Println(s)s = enlarge(s, 5) // calling function to magnifyfmt.Println("The length of s after enlarging is:", len(s))fmt.Println(s)}func enlarge(s []int, factor int) []int {ns := make([]int, len(s) * factor) // making a new slice of length len(s)*factorcopy(ns, s) // copying contents from s to new slicereturn ns}
In the code above, look at the header for function enlarge
...