Big boss function

Report a typo

You have just learned the theory about channels. But your mentor Bob says that the most important thing is practice!

So he created a program template. It should send random length array of numbers to the channel, then print it in the receiver, close the channel and exit.

Your task in this program is to add a function that will create a channel, return a read-only channel to the main program, send data to it and then close it.

This task uses functions randomizer() and isReceiver(). You don't need to know how they work internally. randomizer() creates a slice of int of a given length. isReceiver() checks the type of the returned channel and throws an error if it's not read-only.

Sample Input 1:

6

Sample Output 1:

052443
Write a program in Go
package main

import (
"fmt"
"math/rand"
"time"
)

// complete this function
func sender(data []int) ? int {

}

// DO NOT change the code bellow
func receiver(ch <-chan int) {
for val := range ch {
fmt.Print(val)
}
}

func main() {
var length int
fmt.Scanln(&length)
data := randomizer(length)

ch := sender(data)

if !isReceiver(ch) {
fmt.Println("channel should be read-only")
return
}
go receiver(ch)

time.Sleep(time.Second)
}
___

Create a free account to access the full topic