Решение на Log Parsing от Йордан Пулов

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

Към профила на Йордан Пулов

Резултати

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

Код

package main
func Map(data []string, mapper func(string) string) []string {
//mapped := [len(data)]string{}
mapped := make([]string, len(data))
for i, v := range data {
mapped[i] = mapper(v)
}
return mapped
}
func Filter(data []string, predicate func(string) bool) []string {
filtered := make([]string, 0)
for _, value := range data {
if predicate(value) {
filtered = append(filtered, value)
}
}
return filtered
}
func Any(data []string, predicate func(string) bool) bool {
for _, value := range data {
if predicate(value) {
return true
}
}
return false
}
func All(data []string, predicate func(string) bool) bool {
for _, value := range data {
if !predicate(value) {
return false
}
}
return true
}
func Reduce(data []string, combinator func(string, string) string) string {
reduced_string := ""
for _, v := range data {
reduced_string = combinator(reduced_string, v)
}
return reduced_string
}

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

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

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

Йордан обнови решението на 19.10.2014 21:11 (преди над 3 години)

+package main
+
+func Map(data []string, mapper func(string) string) []string {
+ //mapped := [len(data)]string{}
+ mapped := make([]string, len(data))
+ for i, v := range data {
+ mapped[i] = mapper(v)
+ }
+ return mapped
+}
+
+func Filter(data []string, predicate func(string) bool) []string {
+ //filtered := [len(data)]string{}
+ filtered := make([]string, len(data))
+ for _, value := range data {
+ if predicate(value) {
+ filtered = append(filtered, value)
+ }
+ }
+ return filtered
+}
+
+func Any(data []string, predicate func(string) bool) bool {
+ for _, value := range data {
+ if predicate(value) {
+ return true
+ }
+ }
+ return false
+}
+
+func All(data []string, predicate func(string) bool) bool {
+ for _, value := range data {
+ if !predicate(value) {
+ return false
+ }
+ }
+ return true
+}
+
+// TO BE CONTINUED WITH REDUCE

Йордан обнови решението на 19.10.2014 21:59 (преди над 3 години)

package main
func Map(data []string, mapper func(string) string) []string {
//mapped := [len(data)]string{}
mapped := make([]string, len(data))
for i, v := range data {
mapped[i] = mapper(v)
}
return mapped
}
func Filter(data []string, predicate func(string) bool) []string {
- //filtered := [len(data)]string{}
- filtered := make([]string, len(data))
+
+ filtered := make([]string, 0)
for _, value := range data {
if predicate(value) {
filtered = append(filtered, value)
}
}
return filtered
}
func Any(data []string, predicate func(string) bool) bool {
+
for _, value := range data {
if predicate(value) {
return true
}
}
return false
}
func All(data []string, predicate func(string) bool) bool {
+
for _, value := range data {
if !predicate(value) {
return false
}
}
return true
}
-// TO BE CONTINUED WITH REDUCE
+func Reduce(data []string, combinator func(string, string) string) string {
+
+ reduced_string := ""
+ for _, v := range data {
+ reduced_string = combinator(reduced_string, v)
+ }
+ return reduced_string
+}