Skip to content

Instantly share code, notes, and snippets.

@vporoshok
Created June 11, 2018 16:49
Show Gist options
  • Save vporoshok/dbd7ad4711311394c6fa4b2bfa406af5 to your computer and use it in GitHub Desktop.
Save vporoshok/dbd7ad4711311394c6fa4b2bfa406af5 to your computer and use it in GitHub Desktop.
package fizzbuzz
import (
"strconv"
"strings"
)
// FizzBuzz return "Fizz" for 3*n number, "Buzz" for 5*n number,
// "FizzBuzz" for 15*n number and number as string otherwise.
func FizzBuzz(n int) string {
res := strings.Builder{}
if n%3 == 0 {
res.WriteString("Fizz")
}
if n%5 == 0 {
res.WriteString("Buzz")
}
if res.Len() == 0 {
res.WriteString(strconv.Itoa(n))
}
return res.String()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment