Исмаил обнови решението на 21.10.2018 01:12 (преди 10 месеца)
+package main
+
+import "strings"
+
+func Repeater(word, separator string) func(int) string {
+ return func(times int) string {
+ var words []string
+ for i := 0; i < times; i++ {
+ words = append(words, word)
+ }
+
+ return strings.Join(words, separator)
+ }
+}
+
+func Generator(gen func(int) int, initial int) func() int {
+ is_initial_call := true
+ current := initial
+
+ return func() int {
+ if is_initial_call {
+ is_initial_call = false
+ return initial
+ }
+
+ current = gen(current)
+ return current
+ }
+}
+
+func MapReducer(mapper func(int) int, reducer func(int, int) int, initial int) func(...int) int {
+ return func(nums ...int) int {
+ mapped := make([]int, len(nums))
+ for i := 0; i < len(nums); i++ {
+ mapped[i] = mapper(nums[i])
+ }
+
+ reduced := initial
+ for i := 0; i < len(nums); i++ {
+ reduced = reducer(reduced, mapped[i])
+ }
+
+ return reduced
+ }
+}
Бих се радвал да обратна връзка. Благодаря предварително.