Skip to content

Latest commit

 

History

History

20220516184422

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Named return values in go

Avoid needlessly instantiating return variables!

Instead of:

// Sum each integer in a string of only integers
func countLetterA(input string) int {
  v := 0
  for _, s := range input {
		if s == 'a' {
			v++
		}
  }
  return v

Do:

func countLetterA(input string) (v int) {
  for _, s := range input {
		if s == 'a' {
			v++
		}
  }
  return
#golang #tips