Files
learngo/16-slices/exercises/21-correct-the-lyric/main.go

74 lines
2.0 KiB
Go
Raw Normal View History

2019-10-30 19:34:44 +03:00
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
2019-03-04 20:30:18 +03:00
package main
import (
"fmt"
"strings"
)
// ---------------------------------------------------------
// EXERCISE: Correct the lyric
//
2019-08-18 15:08:32 +03:00
// You have a slice that contains the words of Beatles'
// legendary song: Yesterday. However, the order of the
// words are incorrect.
//
// CURRENT OUTPUT
//
2021-05-01 13:21:56 +03:00
// [all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay]
2019-08-18 15:08:32 +03:00
//
// EXPECTED OUTPUT
//
2021-05-01 13:21:56 +03:00
// [yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday]
2019-03-04 20:30:18 +03:00
//
//
// STEPS
//
2019-08-23 00:33:53 +03:00
// INITIAL SLICE:
2021-05-01 13:21:56 +03:00
// [all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay]
2019-08-23 00:33:53 +03:00
//
//
2019-03-04 20:30:18 +03:00
// 1. Prepend "yesterday" to the `lyric` slice.
//
2019-08-23 00:33:53 +03:00
// RESULT SHOULD BE:
2021-05-01 13:21:56 +03:00
// [yesterday all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay]
2019-08-23 00:33:53 +03:00
//
//
2019-08-18 15:08:32 +03:00
// 2. Put the words to the correct positions in the `lyric` slice.
2019-03-04 20:30:18 +03:00
//
2019-08-23 00:33:53 +03:00
// RESULT SHOULD BE:
2021-05-01 13:21:56 +03:00
// [yesterday all my troubles seemed so far away now it looks as though they are here to stay oh I believe in yesterday]
2019-08-23 00:33:53 +03:00
//
2019-03-04 20:30:18 +03:00
//
2019-08-23 00:33:53 +03:00
// 3. Print the `lyric` slice.
2019-03-04 20:30:18 +03:00
//
//
// BONUS
//
2019-08-18 15:32:48 +03:00
// + Think about when does the append allocate a new backing array.
2019-08-18 15:08:32 +03:00
//
// + Check whether your conclusions are correct.
2019-03-04 20:30:18 +03:00
//
2019-08-23 00:33:53 +03:00
//
// HINTS
//
// If you get stuck, check out the hints.md file.
2019-08-23 00:33:53 +03:00
//
2019-03-04 20:30:18 +03:00
// ---------------------------------------------------------
func main() {
// DON'T TOUCH THIS:
2021-05-01 13:21:56 +03:00
lyric := strings.Fields(`all my troubles seemed so far away oh I believe in yesterday now it looks as though they are here to stay`)
2019-03-04 20:30:18 +03:00
// ADD YOUR CODE BELOW:
// ...
fmt.Printf("%s\n", lyric)
}