Skip to content

Instantly share code, notes, and snippets.

@zaky
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save zaky/0591ffc44b44d21ddf11 to your computer and use it in GitHub Desktop.

Select an option

Save zaky/0591ffc44b44d21ddf11 to your computer and use it in GitHub Desktop.
FizzBuzz closure
package main
import (
"fmt"
)
func setCheck(data map[int]string) func(nidle int) (ret string) {
f := func(nidle int) (ret string) {
for key, val := range data {
if nidle%key == 0 {
ret = ret + val
}
}
return
}
return f
}
func main() {
mp := map[int]string{3: "fizz", 5: "buzz", 6: "go"}
f := setCheck(mp)
for i := 1; i <= 100; i++ {
h := f(i)
if len(h) == 0 {
fmt.Println(i)
} else {
fmt.Println(h)
}
}
}
@zaky

zaky commented Sep 30, 2014

Copy link
Copy Markdown
Author

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