New answers tagged

1

Your first variant is unnecessary detailed and hard to read: an IPv4 address consists of exactly 4 digit groups 4 is a small number, maybe it's worth to inline the for loop the for loop treats the case k == 0 specially the += operator for strings allocates a new string each time the code is much longer than the description in the task "join the four numbers ...


0

an exercise from the Go Tour website I found two ways to achieve the goal but I am wondering if there is no other clean way of doing it. Example 1 with range. Example 2 with a simple fmt.Sprintf Another way (Example 3): package main import ( "fmt" "strconv" ) type IPAddr [4]byte func (ip IPAddr) String() string { s := make([]...


Top 50 recent answers are included