Just sharing some tips.
When working with slices, it is often a good idea to lend a helping hand to the compiler.
Don't declare something like this, unless you have no other choices.
```
var slice []int
```
If you know the data right away, you can do something like this:
```
slice := []int{1,2,3,4,5}
```
If you don't know the data, but you know the size, you can do something like this:
```
slice:=make([]int, 5)
//example: working with slice
for a:=0; a<5; a++ {
slice[a] = a+1
}
```
If you don't know the data and the size, you can do something like this:
```
slice:=make([]int, 0, 5)
//make a slice with 0 length, but allocate memory for 5 items (capacity of 5).
//The capacity can be of any arbitrary length. Think of it like a suggestion of what you think the data size may be.
//example
for a:=0; a<10; a++ {
slice = append(slice, a+1)
//As long as slice length does not exceed its capacity, no new slice is allocated.
//If the length exceed the capacity, the compiler will allocate twice the original capacity or at least enough to store the items (whichever is larger).
//In this case, asuming only one item is appended at a time, append will create new slices with the following capacity: 5, 10, 20, 40, ...
)
```
Now let's see what happens when you do this:
```
var slice []int
for a:=0; a<10; a++ {
slice = append(slice, a+1)
//When a=0, the slice has 0 capacity but need 1, hence a new slice is created with 1 capacity and 1 length.
//When a=1, the slice has 1 capacity but need 2, hence a new slice is created with 2 capacity (twice the original capacity: 2x1) and 2 length.
//When a=2, the slice has 2 capacity but need 3, hence a new slice is created with 4 capacity (twice the original capacity: 2x2) and 3 length.
//When a=3, the slice has 4 capacity and need 4, hence no new slice is created and the existing slice is returned with 4 length.
//When a=4, the slice has 4 capacity but need 5, hence a new slice is created with 8 capacity (twice the original capacity: 2x4) and 5 length.
//When a=5, the slice has 8 capacity and need 6, hence no new slice is created and the existing slice is returned with 6 length.
//etc.
}
```
If you do not specify the length or the capacity, you are bound to create several unnecessary memory allocations. It may not matter much in a real world application, but I think it is a good idea to help out the compiler as long as it is reasonable to do so, and specifying the length or the capacity does not take much effort on your part.