Решение на Log Parsing от Любомир Коев

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

Към профила на Любомир Коев

Резултати

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

Код

package main
func Map(data []string, mapper func(string) string) (result []string) {
result = make([]string, len(data))
for c, item := range data {
result[c] = mapper(item)
}
return
}
func Filter(data []string, predicate func(string) bool) (result []string) {
result = make([]string, 0)
_ = Map(data, func(item string) string {
if predicate(item) {
result = append(result, item)
}
return item
})
return
}
func Reduce(data []string, combinator func(string, string) string) (result string) {
if len(data) == 0 {
return
}
result = data[0]
_ = Map(data[1:], func(item string) string {
result = combinator(result, item)
return item
})
return
}
func Any(data []string, predicate func(string) bool) (result bool) {
_ = Map(data, func(item string) string {
result = result || predicate(item)
return item
})
return
}
func All(data []string, predicate func(string) bool) (result bool) {
result = true
_ = Map(data, func(item string) string {
result = result && predicate(item)
return item
})
return
}

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

PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s
PASS
ok  	_/tmp/d20141023-10368-t21g6s	0.011s

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

Любомир обнови решението на 18.10.2014 01:50 (преди над 3 години)

+package main
+
+func Map(data []string, mapper func(string) string) (result []string) {
+ result = make([]string, len(data))
+ for c, item := range data {
+ result[c] = mapper(item)
+ }
+ return
+}
+
+func Filter(data []string, predicate func(string) bool) (result []string) {
+ result = make([]string, 0)
+ _ = Map(data, func(item string) string {
+ if predicate(item) {
+ result = append(result, item)
+ }
+ return item
+ })
+ return
+}
+
+func Reduce(data []string, combinator func(string, string) string) (result string) {
+ _ = Map(data, func(item string) string {
+ result += item
+ return item
+ })
+ return
+}
+
+func Any(data []string, predicate func(string) bool) (result bool) {
+ result = false
+ _ = Map(data, func(item string) string {
+ result = result || predicate(item)
+ return item
+ })
+ return
+}
+
+func All(data []string, predicate func(string) bool) (result bool) {
+ result = true
+ _ = Map(data, func(item string) string {
+ result = result && predicate(item)
+ return item
+ })
+ return
+}

Любомир обнови решението на 18.10.2014 01:52 (преди над 3 години)

package main
func Map(data []string, mapper func(string) string) (result []string) {
result = make([]string, len(data))
for c, item := range data {
result[c] = mapper(item)
}
return
}
func Filter(data []string, predicate func(string) bool) (result []string) {
result = make([]string, 0)
_ = Map(data, func(item string) string {
if predicate(item) {
result = append(result, item)
}
- return item
+ return ""
})
return
}
func Reduce(data []string, combinator func(string, string) string) (result string) {
_ = Map(data, func(item string) string {
result += item
- return item
+ return ""
})
return
}
func Any(data []string, predicate func(string) bool) (result bool) {
result = false
_ = Map(data, func(item string) string {
result = result || predicate(item)
- return item
+ return ""
})
return
}
func All(data []string, predicate func(string) bool) (result bool) {
result = true
_ = Map(data, func(item string) string {
result = result && predicate(item)
- return item
+ return ""
})
return
}

Любомир обнови решението на 18.10.2014 01:54 (преди над 3 години)

package main
func Map(data []string, mapper func(string) string) (result []string) {
result = make([]string, len(data))
for c, item := range data {
result[c] = mapper(item)
}
return
}
func Filter(data []string, predicate func(string) bool) (result []string) {
result = make([]string, 0)
_ = Map(data, func(item string) string {
if predicate(item) {
result = append(result, item)
}
return ""
})
return
}
func Reduce(data []string, combinator func(string, string) string) (result string) {
_ = Map(data, func(item string) string {
result += item
return ""
})
return
}
func Any(data []string, predicate func(string) bool) (result bool) {
- result = false
_ = Map(data, func(item string) string {
result = result || predicate(item)
return ""
})
return
}
func All(data []string, predicate func(string) bool) (result bool) {
result = true
_ = Map(data, func(item string) string {
result = result && predicate(item)
return ""
})
return
}

Любомир обнови решението на 18.10.2014 13:16 (преди над 3 години)

package main
func Map(data []string, mapper func(string) string) (result []string) {
result = make([]string, len(data))
for c, item := range data {
result[c] = mapper(item)
}
return
}
func Filter(data []string, predicate func(string) bool) (result []string) {
result = make([]string, 0)
_ = Map(data, func(item string) string {
if predicate(item) {
result = append(result, item)
}
return ""
})
return
}
func Reduce(data []string, combinator func(string, string) string) (result string) {
- _ = Map(data, func(item string) string {
- result += item
- return ""
- })
+ if len(data) == 0 {
+ return
+ }
+ result = data[0]
+ for idx, val := range data {
+ if idx > 0 {
+ result = combinator(result, val)
+ }
+ }
return
}
func Any(data []string, predicate func(string) bool) (result bool) {
_ = Map(data, func(item string) string {
result = result || predicate(item)
return ""
})
return
}
func All(data []string, predicate func(string) bool) (result bool) {
result = true
_ = Map(data, func(item string) string {
result = result && predicate(item)
return ""
})
return
}

Любомир обнови решението на 18.10.2014 18:35 (преди над 3 години)

package main
func Map(data []string, mapper func(string) string) (result []string) {
result = make([]string, len(data))
for c, item := range data {
result[c] = mapper(item)
}
return
}
func Filter(data []string, predicate func(string) bool) (result []string) {
result = make([]string, 0)
_ = Map(data, func(item string) string {
if predicate(item) {
result = append(result, item)
}
- return ""
+ return item
})
return
}
func Reduce(data []string, combinator func(string, string) string) (result string) {
if len(data) == 0 {
return
}
result = data[0]
- for idx, val := range data {
- if idx > 0 {
- result = combinator(result, val)
- }
- }
+ _ = Map(data[1:], func(item string) string {
+ result = combinator(result, item)
+ return item
+ })
return
}
func Any(data []string, predicate func(string) bool) (result bool) {
_ = Map(data, func(item string) string {
result = result || predicate(item)
- return ""
+ return item
})
return
}
func All(data []string, predicate func(string) bool) (result bool) {
result = true
_ = Map(data, func(item string) string {
result = result && predicate(item)
- return ""
+ return item
})
return
}

Да за това говорех, но то не е проблем. Аз просто си мисля че Map трябва да мутира подадените данни и забравям че тук условието беше да връща копие.

Общо взето няма значение...