Решение на Log Parsing от Йончо Йончев

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

Към профила на Йончо Йончев

Резултати

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

Код

package main
//map function
func Map(data []string, mapper func(string) string) []string {
array := []string{}
for _, val := range data {
array = append(array, mapper(val))
}
return array
}
//filter function
func Filter(data []string, predicate func(string) bool) []string {
array := []string{}
for _, val := range data {
if predicate(val) {
array = append(array, val)
}
}
return array
}
//reduce function
func Reduce(data []string, combinator func(string, string) string) string {
var result string = ""
for i, val := range data {
if i == 0 {
result = val
} else {
result = combinator(result, val)
}
}
return result
}
// any function
func Any(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) == true {
return true
}
}
return false
}
//all function
func All(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) != true {
return false
}
}
return true
}

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

PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.012s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.019s
PASS
ok  	_/tmp/d20141023-10368-62h7lf	0.011s

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

Йончо обнови решението на 21.10.2014 00:09 (преди над 3 години)

+package main
+
+//map function
+func Map(data []string, mapper func(string) string) []string {
+ array := []string{}
+ for _, val := range data {
+ array = append(array, mapper(val))
+ }
+ return array
+}
+
+//filter function
+func Filter(data []string, predicate func(string) bool) []string {
+ array := []string{}
+ for _, val := range data {
+ if predicate(val) {
+ array = append(array, val)
+ }
+ }
+ return array
+}
+
+//reduce function
+func Reduce(data []string, combinator func(string, string) string) string {
+ var result string = ""
+ for _, val := range data {
+ result = combinator(result, val)
+ }
+ return result
+}
+
+// anyfunction
+func Any(data []string, predicate func(string) bool) bool {
+ for _, val := range data {
+ if predicate(val) == true {
+ return true
+ }
+ }
+ return false
+}
+
+//
+func All(data []string, predicate func(string) bool) bool {
+ for _, val := range data {
+ if predicate(val) != true {
+ return false
+ }
+ }
+ return true
+}
+
+func main() {
+
+}

Йончо обнови решението на 21.10.2014 07:12 (преди над 3 години)

package main
//map function
func Map(data []string, mapper func(string) string) []string {
array := []string{}
for _, val := range data {
array = append(array, mapper(val))
}
return array
}
//filter function
func Filter(data []string, predicate func(string) bool) []string {
array := []string{}
for _, val := range data {
if predicate(val) {
array = append(array, val)
}
}
return array
}
//reduce function
func Reduce(data []string, combinator func(string, string) string) string {
var result string = ""
for _, val := range data {
- result = combinator(result, val)
+ result = result + val
}
- return result
+ return combinator("", result)
}
-// anyfunction
+// any function
func Any(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) == true {
return true
}
}
return false
}
-//
+//all function
func All(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) != true {
return false
}
}
return true
-}
-
-func main() {
-
}

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

package main
//map function
func Map(data []string, mapper func(string) string) []string {
array := []string{}
for _, val := range data {
array = append(array, mapper(val))
}
return array
}
//filter function
func Filter(data []string, predicate func(string) bool) []string {
array := []string{}
for _, val := range data {
if predicate(val) {
array = append(array, val)
}
}
return array
}
//reduce function
func Reduce(data []string, combinator func(string, string) string) string {
var result string = ""
for _, val := range data {
- result = result + val
+ result = combinator(result, val)
}
- return combinator("", result)
+ return result
}
// any function
func Any(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) == true {
return true
}
}
return false
}
//all function
func All(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) != true {
return false
}
}
return true
}

Йончо обнови решението на 21.10.2014 13:16 (преди над 3 години)

package main
//map function
func Map(data []string, mapper func(string) string) []string {
array := []string{}
for _, val := range data {
array = append(array, mapper(val))
}
return array
}
//filter function
func Filter(data []string, predicate func(string) bool) []string {
array := []string{}
for _, val := range data {
if predicate(val) {
array = append(array, val)
}
}
return array
}
//reduce function
func Reduce(data []string, combinator func(string, string) string) string {
var result string = ""
- for _, val := range data {
- result = combinator(result, val)
+ for i, val := range data {
+ if i == 0 {
+ result = val
+ } else {
+ result = combinator(result, val)
+ }
}
return result
}
// any function
func Any(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) == true {
return true
}
}
return false
}
//all function
func All(data []string, predicate func(string) bool) bool {
for _, val := range data {
if predicate(val) != true {
return false
}
}
return true
-}
+}