Зміст курсу
Introduction to GoLang
Introduction to GoLang
Challenge: Reviewing Concepts of Functions
Task
- Finish the code for the second parameter of the
operate
function, which is expected to accept thecapitalize
function; - Review the code and provide suitable arguments in the
operate
function call within themain()
function; - Save the returned values from the
operate
function call into the variablesoriginal
andupdated
.
index.go
Pass
inputString
and capitalize
in the
operate
function call.
package main
import "fmt"
// ToLower() and ToUpper() functions are imported from the `strings` module
import "strings"
func capitalize(str string) string {
return strings.ToUpper(str)
}
func operate(str string, operation func(string) string) (string, string) {
return str, operation(str)
}
func main() {
inputString := "Hello World"
var original string
var updated string
original, updated = operate(inputString, capitalize)
fmt.Println(original, updated)
}
Все було зрозуміло?
Секція 4. Розділ 7
Зміст курсу
Introduction to GoLang
Introduction to GoLang
Challenge: Reviewing Concepts of Functions
Task
- Finish the code for the second parameter of the
operate
function, which is expected to accept thecapitalize
function; - Review the code and provide suitable arguments in the
operate
function call within themain()
function; - Save the returned values from the
operate
function call into the variablesoriginal
andupdated
.
index.go
Pass
inputString
and capitalize
in the
operate
function call.
package main
import "fmt"
// ToLower() and ToUpper() functions are imported from the `strings` module
import "strings"
func capitalize(str string) string {
return strings.ToUpper(str)
}
func operate(str string, operation func(string) string) (string, string) {
return str, operation(str)
}
func main() {
inputString := "Hello World"
var original string
var updated string
original, updated = operate(inputString, capitalize)
fmt.Println(original, updated)
}
Все було зрозуміло?
Секція 4. Розділ 7