Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "syscall/js"
- "strconv"
- )
- func fib(i int, c chan int) {
- var temp int
- prev:=0
- current:=0
- for j:=0;j<=i;j++ {
- if j==1 {
- current=1
- } else {
- temp=current
- current=current+prev
- prev=temp
- }
- }
- c <- current
- }
- func outputME() string {
- c :=make (chan int)
- go fib(9,c)
- d := <-c
- return "Fibonacci of 9 is "+strconv.Itoa(d)
- }
- =
- func main() {
- js.Global().Get("document").Call("getElementById","demo").Set("textContent",outputME())
- }
Advertisement
Add Comment
Please, Sign In to add comment