add: exercises and quiz for appending and slicing
This commit is contained in:
54
16-slices/exercises/13-slicing-basics/main.go
Normal file
54
16-slices/exercises/13-slicing-basics/main.go
Normal file
@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE: Slice the numbers
|
||||
//
|
||||
// We've a string that contains even and odd numbers.
|
||||
//
|
||||
// 1. Convert the string to an []int
|
||||
//
|
||||
// 2. Print the slice
|
||||
//
|
||||
// 3. Slice it for the even numbers and print it (assign it to a new slice variable)
|
||||
//
|
||||
// 4. Slice it for the odd numbers and print it (assign it to a new slice variable)
|
||||
//
|
||||
// 5. Slice it for the two numbers at the middle
|
||||
//
|
||||
// 6. Slice it for the first two numbers
|
||||
//
|
||||
// 7. Slice it for the last two numbers (use the len function)
|
||||
//
|
||||
// 8. Slice the evens slice for the last one number
|
||||
//
|
||||
// 9. Slice the odds slice for the last two numbers
|
||||
//
|
||||
//
|
||||
// EXPECTED OUTPUT
|
||||
// go run main.go
|
||||
//
|
||||
// nums : [2 4 6 1 3 5]
|
||||
// evens : [2 4 6]
|
||||
// odds : [1 3 5]
|
||||
// middle : [6 1]
|
||||
// first 2 : [2 4]
|
||||
// last 2 : [3 5]
|
||||
// evens last 1: [6]
|
||||
// odds last 2 : [4 6]
|
||||
//
|
||||
//
|
||||
// NOTE
|
||||
//
|
||||
// You can also use my prettyslice package for printing the slices.
|
||||
//
|
||||
//
|
||||
// HINT
|
||||
//
|
||||
// Find a function in the strings package for splitting the string into []string
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
|
||||
func main() {
|
||||
// uncomment the declaration below
|
||||
// data := "2 4 6 1 3 5"
|
||||
}
|
Reference in New Issue
Block a user