finished woo

This commit is contained in:
Tommy Parnell
2017-07-08 01:22:34 -04:00
parent 4f33005b26
commit a7d91efcfc
20 changed files with 126 additions and 179 deletions

View File

@@ -3,21 +3,21 @@ package go_koans
func aboutAllocation() {
a := new(int)
*a = 3
assert(*a == __int__) // new() creates a pointer to the given type, like malloc() in C
assert(*a == 3) // new() creates a pointer to the given type, like malloc() in C
type person struct {
name string
age int
}
bob := new(person)
assert(bob.age == __int__) // it can allocate memory for custom types as well
assert(bob.age == 0) // it can allocate memory for custom types as well
slice := make([]int, 3)
assert(len(slice) == __int__) // make() creates slices of a given length
assert(len(slice) == 3) // make() creates slices of a given length
slice = make([]int, 3, __positive_int__) // but can also take an optional capacity
slice = make([]int, 3, 20) // but can also take an optional capacity
assert(cap(slice) == 20)
m := make(map[int]string)
assert(len(m) == __int__) // make() also creates maps
assert(len(m) == 0) // make() also creates maps
}