Created
June 11, 2018 16:49
-
-
Save vporoshok/dbd7ad4711311394c6fa4b2bfa406af5 to your computer and use it in GitHub Desktop.
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
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