add: unfinished code. people are having problems
This commit is contained in:
33
14-arrays/02-examples-1-hipsters-love-bookstore/main.go
Normal file
33
14-arrays/02-examples-1-hipsters-love-bookstore/main.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
// STORY:
|
||||
// Hipster's Love store publishes limited books
|
||||
// twice a year.
|
||||
//
|
||||
// The number of books they publish is fixed at 4.
|
||||
|
||||
// So, let's create a 4 elements string array for the books.
|
||||
|
||||
const (
|
||||
winter = 1
|
||||
summer = 3
|
||||
yearly = winter + summer
|
||||
)
|
||||
|
||||
func main() {
|
||||
// var books [4]string
|
||||
// var books [1 + 3]string
|
||||
var books [yearly]string
|
||||
|
||||
books[0] = "Kafka's Revenge"
|
||||
books[1] = "Stay Golden"
|
||||
books[2] = "Everythingship"
|
||||
books[3] += books[0] + " 2nd Edition"
|
||||
|
||||
// Go compiler can catch indexing errors when constant is used
|
||||
// books[4] = "Neverland"
|
||||
|
||||
// Go compiler cannot catch indexing errors when non-constant is used
|
||||
// i := 4
|
||||
// books[i] = "Neverland"
|
||||
}
|
Reference in New Issue
Block a user