Решение на Poor Man's Currying от Ива Милушева

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

Към профила на Ива Милушева

Резултати

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

Код

package main
func Repeater(s, sep string) func(int) string {
return func(num int) string {
result := s
for i := 0; i < num; i++ {
if i != num-2 {
result += sep + s
}
}
return result
}
}
func Generator(gen func(int) int, initial int) func() int {
return func() int {
defer func() { initial = gen(initial) }()
return initial
}
}
func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
return func(arr ...int) int {
for _, num := range arr {
initial = reducer(mapper(num), initial)
}
return initial
}
}

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

PASS
ok  	_/tmp/d20181024-53-fdlgwt	0.002s
--- FAIL: TestRepeater (0.00s)
    --- FAIL: TestRepeater/zero_repeats (0.00s)
        solution_test.go:129: Expected `` but got `gopher`
    --- FAIL: TestRepeater/one_repeats (0.00s)
        solution_test.go:129: Expected `gopher` but got `gopher-gopher`
FAIL
exit status 1
FAIL	_/tmp/d20181024-53-fdlgwt	0.003s
PASS
ok  	_/tmp/d20181024-53-fdlgwt	0.004s
PASS
ok  	_/tmp/d20181024-53-fdlgwt	0.002s
--- FAIL: TestMapReducer (0.00s)
    --- FAIL: TestMapReducer/left_shift_all_the_way (0.00s)
        solution_test.go:291: Expected 88080384 but got 0
    --- FAIL: TestMapReducer/left_foldedness (0.00s)
        solution_test.go:291: Expected 64 but got 0
FAIL
exit status 1
FAIL	_/tmp/d20181024-53-fdlgwt	0.002s
--- FAIL: TestMapReducerMultipleCalls (0.00s)
    solution_test.go:318: Expected 45 but got 81 after 2nd call
FAIL
exit status 1
FAIL	_/tmp/d20181024-53-fdlgwt	0.002s

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

Ива обнови решението на 23.10.2018 22:37 (преди 10 месеца)

+package main
+
+func Repeater(s, sep string) func(int) string {
+
+ return func(num int) string {
+ result := s
+ for i := 0; i < num; i++ {
+
+ if i != num-2 {
+ result += sep + s
+ }
+
+ }
+ return result
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ return func() int {
+ defer func() { initial = gen(initial) }()
+ return initial
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+
+ return func(arr ...int) int {
+ for _, num := range arr {
+ initial = reducer(mapper(num), initial)
+
+ }
+ return initial
+ }
+
+}