Slice Exercises
Exercises Level I - Basics — Warm-Up
Let's reinforce your basic knowledge of slices.
-
Declare nil slices
-
Assign empty slices
-
Assign slice literals
-
Declare the arrays as slices
-
Fix the Problems
-
Compare the slices
Exercises Level II - Appending
Discover the power of the append function.
-
Append #1 — Append and compare byte slices
-
Append #2 — Append to a nil slice
-
Append #3 — Fix the problems
-
Append and Sort Numbers
-
Housing Prices
-
Housing Prices and Averages
Exercises Level III - Slicing
Discover the power of slicing.
-
Slice the numbers
-
Slicing by arguments
-
Slicing the Housing Prices
Exercises Level IV - Internals
Peek into the internals of the slices and gain more insight. This is necessary for complete command of the slices.
-
Fix the backing array problems
-
Sort the backing array
-
Observe the memory allocations
-
Observe the length and capacity
-
Observe the capacity growth
-
Correct the lyric
Exercises Level V - Advanced Operations
Commonly used and more advanced operations are available to slices. Now, it's time to test yourself and fix some common problems.
★ WARNING ★
Please update your local copy of the prettyslice package for some examples to work. Please find the intructions how to do so here.
-
Practice Advanced Slice Operations
Let's warm you up for the advanced slice operations, and reinforce your neurons.
-
Limit the backing array sharing
Your package needs to control the slices that it shares with the outside world.
-
Fix the Memory Leak
A slice retrieved from a package causes a memory leak in your program. You need to fix it.
-
Add a newline after each sentence
Use the power of the copy()
function and add newlines into a new buffer from a string slice. This exercise is more tricky than you might think.
-
Print Daily Requests
Group the web request logs into a multi-dimensional slice. Allocate a slice with the exact size needed by doing some wizardary calculations. And lastly, pretty print the result.