Решение на Log Parsing от Стоян Трифонов

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

Към профила на Стоян Трифонов

Резултати

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

Код

package main
func All(data []string, predicate func(string) bool) bool {
for _, value := range data {
if predicate(value) == false {
return false
}
}
return true
}
func Any(data []string, predicate func(string) bool) bool {
for _, value := range data {
if predicate(value) {
return true
}
}
return false
}
func Map(data []string, mutator func(string) string) []string {
slice := make([]string, 0, len(data))
for _, value := range data {
slice = append(slice, mutator(value))
}
return slice
}
func Filter(data []string, predicate func(string) bool) []string {
slice := make([]string, 0, len(data))
for _, value := range data {
if predicate(value) {
slice = append(slice, value)
}
}
return slice
}
func Reduce(data []string, combinator func(string, string) string) string {
result := ""
for _, value := range data {
result = combinator(result, value)
}
return result
}

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

PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s
PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s
PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s
PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s
PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s
--- FAIL: TestReduceOneElement (0.00 seconds)
	solution_test.go:100: expected [pesho] got [50]
FAIL
exit status 1
FAIL	_/tmp/d20141023-10368-110ayj9	0.011s
--- FAIL: TestReduceOneElement (0.00 seconds)
	solution_test.go:100: expected [pesho] got [50]
FAIL
exit status 1
FAIL	_/tmp/d20141023-10368-110ayj9	0.011s
PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s
PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s
PASS
ok  	_/tmp/d20141023-10368-110ayj9	0.011s

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

Стоян обнови решението на 21.10.2014 11:43 (преди над 3 години)

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