Решение на Poor Man's Currying от Михаела Михаела

Обратно към всички решения

Към профила на Михаела Михаела

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 6 неуспешни тест(а)

Код

package main
import "fmt"
func Repeater(s, sep string) func(n int) string {
return func(n int) string {
result := ""
for ; n > 1; n-- {
result = result + s + sep
}
if n > 0 {
result := result + s
return result
} else {
fmt.Println("try again ;)")
return result
}
}
}
func main() {
rep := Repeater("sss", "-")(3)
fmt.Println(rep)
}

Лог от изпълнението

# _/tmp/d20181024-53-1nqpu8n [_/tmp/d20181024-53-1nqpu8n.test]
./solution_test.go:20:15: undefined: MapReducer
./solution_test.go:35:14: undefined: Generator
./solution_test.go:39:12: undefined: Generator
./solution_test.go:199:11: undefined: Generator
./solution_test.go:288:16: undefined: MapReducer
./solution_test.go:298:14: undefined: MapReducer
FAIL	_/tmp/d20181024-53-1nqpu8n [build failed]
# _/tmp/d20181024-53-1nqpu8n [_/tmp/d20181024-53-1nqpu8n.test]
./solution_test.go:20:15: undefined: MapReducer
./solution_test.go:35:14: undefined: Generator
./solution_test.go:39:12: undefined: Generator
./solution_test.go:199:11: undefined: Generator
./solution_test.go:288:16: undefined: MapReducer
./solution_test.go:298:14: undefined: MapReducer
FAIL	_/tmp/d20181024-53-1nqpu8n [build failed]
# _/tmp/d20181024-53-1nqpu8n [_/tmp/d20181024-53-1nqpu8n.test]
./solution_test.go:20:15: undefined: MapReducer
./solution_test.go:35:14: undefined: Generator
./solution_test.go:39:12: undefined: Generator
./solution_test.go:199:11: undefined: Generator
./solution_test.go:288:16: undefined: MapReducer
./solution_test.go:298:14: undefined: MapReducer
FAIL	_/tmp/d20181024-53-1nqpu8n [build failed]
# _/tmp/d20181024-53-1nqpu8n [_/tmp/d20181024-53-1nqpu8n.test]
./solution_test.go:20:15: undefined: MapReducer
./solution_test.go:35:14: undefined: Generator
./solution_test.go:39:12: undefined: Generator
./solution_test.go:199:11: undefined: Generator
./solution_test.go:288:16: undefined: MapReducer
./solution_test.go:298:14: undefined: MapReducer
FAIL	_/tmp/d20181024-53-1nqpu8n [build failed]
# _/tmp/d20181024-53-1nqpu8n [_/tmp/d20181024-53-1nqpu8n.test]
./solution_test.go:20:15: undefined: MapReducer
./solution_test.go:35:14: undefined: Generator
./solution_test.go:39:12: undefined: Generator
./solution_test.go:199:11: undefined: Generator
./solution_test.go:288:16: undefined: MapReducer
./solution_test.go:298:14: undefined: MapReducer
FAIL	_/tmp/d20181024-53-1nqpu8n [build failed]
# _/tmp/d20181024-53-1nqpu8n [_/tmp/d20181024-53-1nqpu8n.test]
./solution_test.go:20:15: undefined: MapReducer
./solution_test.go:35:14: undefined: Generator
./solution_test.go:39:12: undefined: Generator
./solution_test.go:199:11: undefined: Generator
./solution_test.go:288:16: undefined: MapReducer
./solution_test.go:298:14: undefined: MapReducer
FAIL	_/tmp/d20181024-53-1nqpu8n [build failed]

История (1 версия и 1 коментар)

Михаела обнови решението на 23.10.2018 23:43 (преди 10 месеца)

+package main
+
+import "fmt"
+
+func Repeater(s, sep string) func(n int) string {
+
+ return func(n int) string {
+ result := ""
+ for ; n > 1; n-- {
+ result = result + s + sep
+ }
+ if n > 0 {
+ result := result + s
+ return result
+ } else {
+ fmt.Println("try again ;)")
+ return result
+ }
+ }
+}
+
+func main() {
+ rep := Repeater("sss", "-")(3)
+ fmt.Println(rep)
+}

За да можеш да получиш поне някакви точки ще е добре да дефинираш и другите два метода в решението си. Дори и да не правят нищо. Също така, не ти трябва main функцията в предаденото решение. Ако искаш да си тестваш с нея, може да я сложиш в съседен файл и да пускаш всичко с go run .