Files
learngo/16-slices/exercises
2022-04-04 17:34:24 +03:00
..
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2019-10-30 19:41:13 +03:00
2021-09-12 00:01:01 +03:00
2021-06-08 11:19:26 +03:00
2019-10-30 19:41:13 +03:00
2021-06-08 11:19:26 +03:00
2019-10-30 19:41:13 +03:00
2019-08-18 15:43:09 +03:00

Slice Exercises

Exercises Level I - Basics — Warm-Up

Let's reinforce your basic knowledge of slices.

  1. Declare nil slices

  2. Assign empty slices

  3. Assign slice literals

  4. Declare the arrays as slices

  5. Fix the Problems

  6. Compare the slices


Exercises Level II - Appending

Discover the power of the append function.

  1. Append #1 — Append and compare byte slices

  2. Append #2 — Append to a nil slice

  3. Append #3 — Fix the problems

  4. Append and Sort Numbers

  5. Housing Prices

  6. Housing Prices and Averages


Exercises Level III - Slicing

Discover the power of slicing.

  1. Slice the numbers

  2. Slicing by arguments

  3. 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.

  1. Fix the backing array problems

  2. Sort the backing array

  3. Observe the memory allocations

  4. Observe the length and capacity

  5. Observe the capacity growth

  6. 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.

  1. Practice Advanced Slice Operations

    Let's warm you up for the advanced slice operations, and reinforce your neurons.

  2. Limit the backing array sharing

    Your package needs to control the slices that it shares with the outside world.

  3. Fix the Memory Leak

    A slice retrieved from a package causes a memory leak in your program. You need to fix it.

  4. 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.

  5. 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.