From 23afa88d0890827b191e29114fe8ced0cede30af Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Fri, 8 Feb 2019 14:10:56 +0300 Subject: [PATCH] fix: reformatted backing array and slice header exercises --- .../16-internals-backing-array-fix/main.go | 2 +- .../17-internals-backing-array-sort/main.go | 3 +- .../18-internals-slice-header/main.go | 37 ++++++++++--------- .../solution/main.go | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/16-slices/exercises/16-internals-backing-array-fix/main.go b/16-slices/exercises/16-internals-backing-array-fix/main.go index c15c56f..21b15c4 100644 --- a/16-slices/exercises/16-internals-backing-array-fix/main.go +++ b/16-slices/exercises/16-internals-backing-array-fix/main.go @@ -27,7 +27,7 @@ import ( // // RESTRICTION // -// Fix your problem only in the designated area of the code below. +// Fix the problem only in the designated area of the code below. // // // EXPECTED OUTPUT diff --git a/16-slices/exercises/17-internals-backing-array-sort/main.go b/16-slices/exercises/17-internals-backing-array-sort/main.go index b993d2e..379bae7 100644 --- a/16-slices/exercises/17-internals-backing-array-sort/main.go +++ b/16-slices/exercises/17-internals-backing-array-sort/main.go @@ -28,7 +28,7 @@ import ( // // Original: [pacman mario tetris doom galaga frogger asteroids simcity metroid defender rayman tempest ultima] // -// Sorted : [pacman mario tetris doom galaga asteroids frogger simcity metroid defender rayman tempest ultima] +// Sorted : [pacman mario tetris doom galaga asteroids frogger simcity metroid defender rayman tempest ultima] // // // HINT: @@ -47,6 +47,7 @@ func main() { } fmt.Println("Original:", items) + // ADD YOUR CODE HERE fmt.Println() fmt.Println("Sorted :", items) } diff --git a/16-slices/exercises/18-internals-slice-header/main.go b/16-slices/exercises/18-internals-slice-header/main.go index 779d6cc..65fd43a 100644 --- a/16-slices/exercises/18-internals-slice-header/main.go +++ b/16-slices/exercises/18-internals-slice-header/main.go @@ -25,17 +25,17 @@ import ( // the same on your own system as well (if you're on 64-bit machine). // // -// <<< initial memory usage >>> +// [initial memory usage] // > Memory Usage: 104 KB -// <<< after declaring an array >>> +// [after declaring an array] // > Memory Usage: 78235 KB -// <<< after copying the array >>> +// [after copying the array] // > Memory Usage: 156365 KB -// <<< inside passArray >>> +// [inside passArray] // > Memory Usage: 234495 KB -// <<< after slicings >>> +// [after slicings] // > Memory Usage: 234497 KB -// <<< inside passSlice >>> +// [inside passSlice] // > Memory Usage: 234497 KB // // Array's size : 80000000 bytes. @@ -47,16 +47,19 @@ import ( // // HINTS // -// I've declared a few function to help you. +// I've declared a few functions to help you. // -// report function prints the memory usage. -// Just call it with a message that matches to the expected output. +// report function: +// - Prints the memory usage. +// - Just call it with a message that matches to the expected output. // -// passArray function accepts a [size]int array, so you can pass it -// your array. It automatically prints the memory usage. +// passArray function: +// - Accepts a [size]int array, so you can pass it your array. +// - It automatically prints the memory usage. // -// passSlice function accepts an int slice, so you can pass it -// your one of your slices. It automatically prints the memory usage. +// passSlice function: +// - Accepts an int slice, so you can pass it one of your slices. +// - It automatically prints the memory usage. // // --------------------------------------------------------- @@ -78,14 +81,14 @@ func main() { // 3. copy the array to a new array (just assign) // 4. print the memory usage - // 5. pass the array to passArray function + // 5. pass the array to the passArray function - // 6. convert the array to a slice (by slicing) + // 6. convert the one of the arrays to a slice (by slicing) // 7. slice only the first 1000 elements of the array // 8. slice only the elements of the array between 1000 and 10000 // 9. print the memory usage - // 10. pass the one of the slices to passSlice function + // 10. pass the one of the slices to the passSlice function // 11. print the sizes of the arrays and slices // hint: use the unsafe.Sizeof function @@ -110,6 +113,6 @@ func passSlice(items []int) { func report(msg string) { var m runtime.MemStats runtime.ReadMemStats(&m) - fmt.Printf("<<< %s >>>\n", msg) + fmt.Printf("[%s]\n", msg) fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024) } diff --git a/16-slices/exercises/18-internals-slice-header/solution/main.go b/16-slices/exercises/18-internals-slice-header/solution/main.go index 6dab275..f706765 100644 --- a/16-slices/exercises/18-internals-slice-header/solution/main.go +++ b/16-slices/exercises/18-internals-slice-header/solution/main.go @@ -57,6 +57,6 @@ func passSlice(items []int) { func report(msg string) { var m runtime.MemStats runtime.ReadMemStats(&m) - fmt.Printf("<<< %s >>>\n", msg) + fmt.Printf("[%s]\n", msg) fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024) }