forked from quii/learn-go-with-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use parameter type instead of named result parameter
- Loading branch information
1 parent
6359ce7
commit 7567e6b
Showing
23 changed files
with
116 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package main | ||
|
||
func Sum(numbers [5]int) (sum int) { | ||
func Sum(numbers [5]int) int { | ||
sum := 0 | ||
for i := 0; i < 5; i++ { | ||
sum += numbers[i] | ||
} | ||
return | ||
return sum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package main | ||
|
||
func Sum(numbers [5]int) (sum int) { | ||
func Sum(numbers [5]int) int { | ||
sum := 0 | ||
for _, number := range numbers { | ||
sum += number | ||
} | ||
return | ||
return sum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package main | ||
|
||
func Sum(numbers []int) (sum int) { | ||
func Sum(numbers []int) int { | ||
sum := 0 | ||
for _, number := range numbers { | ||
sum += number | ||
} | ||
return | ||
return sum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
package main | ||
|
||
func Sum(numbers []int) (sum int) { | ||
func Sum(numbers []int) int { | ||
sum := 0 | ||
for _, number := range numbers { | ||
sum += number | ||
} | ||
return | ||
return sum | ||
} | ||
|
||
func SumAll(numbersToSum ...[]int) (sums []int) { | ||
|
||
func SumAll(numbersToSum ...[]int) []int { | ||
lengthOfNumbers := len(numbersToSum) | ||
sums = make([]int, lengthOfNumbers) | ||
sums := make([]int, lengthOfNumbers) | ||
|
||
for i, numbers := range numbersToSum { | ||
sums[i] = Sum(numbers) | ||
} | ||
|
||
return | ||
return sums | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package main | ||
|
||
func Sum(numbers []int) (sum int) { | ||
func Sum(numbers []int) int { | ||
sum := 0 | ||
for _, number := range numbers { | ||
sum += number | ||
} | ||
return | ||
return sum | ||
} | ||
|
||
func SumAll(numbersToSum ...[]int) (sums []int) { | ||
func SumAll(numbersToSum ...[]int) []int { | ||
var sums []int | ||
for _, numbers := range numbersToSum { | ||
sums = append(sums, Sum(numbers)) | ||
} | ||
|
||
return | ||
return sums | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
package main | ||
|
||
func Sum(numbers []int) (sum int) { | ||
func Sum(numbers []int) int { | ||
sum := 0 | ||
for _, number := range numbers { | ||
sum += number | ||
} | ||
return | ||
return sum | ||
} | ||
|
||
func SumAllTails(numbersToSum ...[]int) (sums []int) { | ||
func SumAllTails(numbersToSum ...[]int) []int { | ||
var sums []int | ||
for _, numbers := range numbersToSum { | ||
tail := numbers[1:] | ||
sums = append(sums, Sum(tail)) | ||
} | ||
|
||
return | ||
return sums | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package main | ||
|
||
func Repeat(character string) (repeated string) { | ||
func Repeat(character string) string { | ||
var repeated string | ||
for i := 0; i < 5; i++ { | ||
repeated = repeated + character | ||
} | ||
return | ||
return repeated | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package main | ||
|
||
func Add(x, y int) (sum int) { | ||
func Add(x, y int) int { | ||
return x + y | ||
} |
Oops, something went wrong.