Решение на Log Parsing от Мартин Добрев

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

Към профила на Мартин Добрев

Резултати

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

Код

package main
func Map(data []string, mutator func(string) string) []string {
result := make([]string, len(data))
for index, value := range data {
result[index] = mutator(value)
}
return result
}
func Filter(data []string, predicate func(string) bool) []string {
result := make([]string, 0)
for _, value := range data {
if predicate(value) {
result = append(result, value)
}
}
return result
}
func Reduce(data []string, combinator func(string, string) string) string {
size := len(data)
if size == 0 {
return ""
}
result := data[0]
for i := 1; i < size; i++ {
result = combinator(result, data[i])
}
return result
}
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
}

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

PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.017s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.014s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s
PASS
ok  	_/tmp/d20141023-10368-33n53y	0.011s

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

Мартин обнови решението на 18.10.2014 14:51 (преди над 3 години)

+package main
+
+func Map(data []string, mutator func(string) string) []string {
+ result := make([]string, len(data))
+ lenght := len(data)
+ for i := 0; i < lenght; i++ {
+ result[i] = mutator(data[i])
+ }
+ return result
+}
+
+func Filter(data []string, predicate func(string) bool) []string {
+ result := make([]string, 1)
+ lenght := len(data)
+ for i := 0; i < lenght; i++ {
+ if predicate(data[i]) {
+ result = append(result, data[i])
+ }
+ }
+ return result
+}
+
+func Reduce(data []string, combinator func(string, string) string) string {
+ var result string
+ lenght := len(data)
+ for i := 0; i < lenght; i++ {
+ result = combinator(result, data[i])
+ }
+ return result
+}
+
+func All(data []string, predicate func(string) bool) bool {
+ lenght := len(data)
+ for i := 0; i < lenght; i++ {
+ if predicate(data[i]) == false {
+ return false
+ }
+ }
+ return true
+}
+
+func Any(data []string, predicate func(string) bool) bool {
+ lenght := len(data)
+ for i := 0; i < lenght; i++ {
+ if predicate(data[i]) == true {
+ return true
+ }
+ }
+ return false
+}

Мартин обнови решението на 18.10.2014 18:36 (преди над 3 години)

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

Мартин обнови решението на 18.10.2014 18:59 (преди над 3 години)

package main
func Map(data []string, mutator func(string) string) []string {
result := make([]string, len(data))
for index, value := range data {
result[index] = mutator(value)
}
return result
}
func Filter(data []string, predicate func(string) bool) []string {
result := make([]string, 0)
for _, value := range data {
if predicate(value) {
result = append(result, value)
}
}
return result
}
func Reduce(data []string, combinator func(string, string) string) string {
- result := ""
- for _, value := range data {
- result = combinator(result, value)
+ size := len(data)
+ if size == 0 {
+ return ""
+ }
+ result := data[0]
+ for i := 1; i < size; i++ {
+ result = combinator(result, data[i])
}
return result
}
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) == true {
return true
}
}
return false
}

Мартин обнови решението на 19.10.2014 13:40 (преди над 3 години)

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

Мартин обнови решението на 20.10.2014 14:25 (преди над 3 години)

package main
func Map(data []string, mutator func(string) string) []string {
result := make([]string, len(data))
for index, value := range data {
result[index] = mutator(value)
}
return result
}
func Filter(data []string, predicate func(string) bool) []string {
result := make([]string, 0)
for _, value := range data {
if predicate(value) {
result = append(result, value)
}
}
return result
}
func Reduce(data []string, combinator func(string, string) string) string {
size := len(data)
if size == 0 {
return ""
}
result := data[0]
for i := 1; i < size; i++ {
result = combinator(result, data[i])
}
return result
}
func All(data []string, predicate func(string) bool) bool {
for _, value := range data {
- if predicate(value) {
+ 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
}