mad_alien

Golang WASM test

Nov 11th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.50 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "syscall/js"
  5.     "strconv"
  6. )
  7.  
  8. func fib(i int, c chan int) {
  9.     var temp int
  10.     prev:=0
  11.     current:=0
  12.     for j:=0;j<=i;j++ {
  13.         if j==1 {
  14.             current=1
  15.         } else {
  16.             temp=current
  17.             current=current+prev
  18.             prev=temp
  19.         }
  20.     }
  21.     c <- current
  22. }
  23.  
  24.  
  25. func outputME() string {
  26.     c :=make (chan int)
  27.     go fib(9,c)
  28.     d  := <-c
  29.     return "Fibonacci of 9 is "+strconv.Itoa(d)
  30. }
  31. =
  32. func main() {
  33.  
  34.     js.Global().Get("document").Call("getElementById","demo").Set("textContent",outputME())
  35. }
Advertisement
Add Comment
Please, Sign In to add comment