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

66 lines
1.7 KiB
Go
Raw Normal View History

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
//
// [all my troubles seemed so far away oh i believe in yesterday now it looks as though they are here to stay]
//
// EXPECTED OUTPUT
//
// [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:
// [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
// 1. Prepend "yesterday" to the `lyric` slice.
//
2019-08-23 00:33:53 +03:00
// RESULT SHOULD BE:
// [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-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:
// [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
//
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:
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`)
// ADD YOUR CODE BELOW:
// ...
fmt.Printf("%s\n", lyric)
}