The problem
Full the answer in order that it reverses the string handed into it.
'world' => 'dlrow'
'phrase' => 'drow'
The answer in Golang
Possibility 1:
package deal answer
func Resolution(phrase string) (out string) {
for _, v := vary phrase {
out = string(v) + out
}
return
}
Possibility 2:
package deal answer
import "strings"
func Resolution(phrase string) string {
var b strings.Builder
for i:=len(phrase)-1; i>-1; i-- {
b.WriteByte(phrase[i])
}
return b.String()
}
Possibility 3:
package deal answer
import "strings"
func Resolution(phrase string) string {
var reversed []string
for i := vary(phrase) {
reversed = append(reversed, string(phrase[len(word)-1-i]))
}
return strings.Be part of(reversed, "")
}
Take a look at instances to validate our answer
package deal solution_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Take a look at Instance", func() {
It("ought to take a look at that the answer returns the proper worth", func() {
Anticipate(Resolution("world")).To(Equal("dlrow"))
Anticipate(Resolution("whats up")).To(Equal("olleh"))
Anticipate(Resolution("")).To(Equal(""))
Anticipate(Resolution("h")).To(Equal("h"))
})
})