Skip to content

Instantly share code, notes, and snippets.

@hunterloftis
Created August 1, 2017 14:27
Show Gist options
  • Save hunterloftis/a11c51c7216a891553505ec114300bec to your computer and use it in GitHub Desktop.
Save hunterloftis/a11c51c7216a891553505ec114300bec to your computer and use it in GitHub Desktop.
for (let i = 1; i <= 100; i++) {
const match = []
if (i % 3 === 0) match.push('fizz')
if (i % 5 === 0) match.push('buzz')
if (match.length === 0) match.push(i)
console.log(match.join(''))
}
@hunterloftis
Copy link
Author

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	for i := 1; i <= 100; i++ {
		match := []string{}
		if i%3 == 0 {
			match = append(match, "fizz")
		}
		if i%5 == 0 {
			match = append(match, "buzz")
		}
		if len(match) == 0 {
			match = append(match, strconv.Itoa(i))
		}
		fmt.Println(strings.Join(match, ""))
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment