Skip to content

Commit 43fd436

Browse files
authored
Merge pull request #81 from pityonline/fix-arrays-and-slices
trivial grammar & style tweak on arrays-and-slices
2 parents 2f9a56d + c25e512 commit 43fd436

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

arrays-and-slices.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func TestSum(t *testing.T) {
3636
Arrays have a _fixed capacity_ which you define when you declare the variable.
3737
We can initialize array in two ways:
3838

39-
* \[N\]type{value1, value2, ..., valueN} e.g. `numbers := [5]int{1, 2, 3, 4, 5}`
40-
* \[...\]type{value1, value2, ..., valueN} e.g. `numbers := [...]int{1, 2, 3, 4, 5}`
39+
* \[N\]type{value1, value2, ..., valueN} e.g. `numbers := [5]int{1, 2, 3, 4, 5}`
40+
* \[...\]type{value1, value2, ..., valueN} e.g. `numbers := [...]int{1, 2, 3, 4, 5}`
4141

4242
It is sometimes useful to also print the inputs to the function in the error
4343
message and we are using the `%v` placeholder which is the "default" format,
@@ -78,12 +78,12 @@ func Sum(numbers [5]int) int {
7878
```
7979

8080
To get the value out of an array at a particular index, just use `array[index]`
81-
syntax. In this case we are using `for` to iterate 5 times to work through the
81+
syntax. In this case, we are using `for` to iterate 5 times to work through the
8282
array and add each item onto `sum`.
8383

8484
### A note on source control
8585

86-
At this point if you are using source control \(which you should!\) I would
86+
At this point, if you are using source control \(which you should!\) I would
8787
`commit` the code as it is. We have working software backed by a test.
8888

8989
I _wouldn't_ push to master though, because I plan to refactor next. It is nice
@@ -199,7 +199,7 @@ It turns out that fixing the compiler problems were all we need to do here and t
199199

200200
## Refactor
201201

202-
We had already refactored `Sum` and all we've done is change from arrays to slices, so there's not a lot to do here. Remember that we must not neglect our test code in the refactoring stage and we have some to do here.
202+
We had already refactored `Sum` and all we've done is changing from arrays to slices, so there's not a lot to do here. Remember that we must not neglect our test code in the refactoring stage and we have some to do here.
203203

204204
```go
205205
func TestSum(t *testing.T) {
@@ -258,7 +258,7 @@ coverage: 100.0% of statements
258258

259259
Now delete one of the tests and check the coverage again.
260260

261-
Now that we are happy we have a well tested function you should commit your
261+
Now that we are happy we have a well-tested function you should commit your
262262
great work before taking on the next challenge.
263263

264264
We need a new function called `SumAll` which will take a varying number of
@@ -275,7 +275,7 @@ or
275275
## Write the test first
276276

277277
```go
278-
func TestSumAll(t *testing.T) {
278+
func TestSumAll(t *testing.T) {
279279

280280
got := SumAll([]int{1,2}, []int{0,9})
281281
want := []int{3, 9}
@@ -308,11 +308,11 @@ Try to compile but our tests still don't compile!
308308

309309
Go does not let you use equality operators with slices. You _could_ write
310310
a function to iterate over each `got` and `want` slice and check their values
311-
but for convenience sake we can use [`reflect.DeepEqual`][deepEqual] which is
311+
but for convenience sake, we can use [`reflect.DeepEqual`][deepEqual] which is
312312
useful for seeing if _any_ two variables are the same.
313313

314314
```go
315-
func TestSumAll(t *testing.T) {
315+
func TestSumAll(t *testing.T) {
316316

317317
got := SumAll([]int{1,2}, []int{0,9})
318318
want := []int{3, 9}
@@ -330,7 +330,7 @@ will compile even if you did something a bit silly. To see this in action,
330330
temporarily change the test to:
331331

332332
```go
333-
func TestSumAll(t *testing.T) {
333+
func TestSumAll(t *testing.T) {
334334

335335
got := SumAll([]int{1,2}, []int{0,9})
336336
want := "bob"
@@ -397,7 +397,7 @@ func SumAll(numbersToSum ...[]int) []int {
397397
}
398398
```
399399

400-
In this implementation we are worrying less about capacity. We start with an
400+
In this implementation, we are worrying less about capacity. We start with an
401401
empty slice \(defined in the function signature\) and append to it the result of
402402
`Sum` as we work through the varargs.
403403

@@ -408,7 +408,7 @@ all the items apart from the first one \(the "head"\)
408408
## Write the test first
409409

410410
```go
411-
func TestSumAllTails(t *testing.T) {
411+
func TestSumAllTails(t *testing.T) {
412412
got := SumAllTails([]int{1,2}, []int{0,9})
413413
want := []int{2, 9}
414414

@@ -444,22 +444,22 @@ func SumAllTails(numbersToSum ...[]int) []int {
444444

445445
Slices can be sliced! The syntax is `slice[low:high]` If you omit the value on
446446
one of the sides of the `:` it captures everything to the side of it. In our
447-
case we are saying take from 1 to the end with `numbers[1:]`. You might want to
448-
invest some time writing other tests around slices and experimenting with the
447+
case, we are saying take from 1 to the end with `numbers[1:]`. You might want to
448+
invest some time in writing other tests around slices and experimenting with the
449449
slice operator so you can be familiar with it.
450450

451451
## Refactor
452452

453453
Not a lot to refactor this time.
454454

455455
What do you think would happen if you passed in an empty array into our
456-
function? What is the "tail" of an empty array? What happens when you tell go to
456+
function? What is the "tail" of an empty array? What happens when you tell Go to
457457
capture all elements from `myEmptySlice[1:]`. ?
458458

459459
## Write the test first
460460

461461
```go
462-
func TestSumAllTails(t *testing.T) {
462+
func TestSumAllTails(t *testing.T) {
463463

464464
t.Run("make the sums of some slices", func(t *testing.T) {
465465
got := SumAllTails([]int{1,2}, []int{0,9})
@@ -571,7 +571,7 @@ slices. Try writing more tests to demonstrate what you learn from reading it.
571571

572572
Another handy way to experiment with Go other than writing tests is the Go
573573
playground. You can try most things out and you can easily share your code if
574-
you need to ask questions. [I have made a go playground with a slice in it for you to experiment with](https://play.golang.org/p/ICCWcRGIO68)
574+
you need to ask questions. [I have made a go playground with a slice in it for you to experiment with.](https://play.golang.org/p/ICCWcRGIO68)
575575

576576
[for]: ../iteration.md#
577577
[blog-slice]: https://blog.golang.org/go-slices-usage-and-internals

0 commit comments

Comments
 (0)