@kjk1/

book slice filter simple

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6518679414369459","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCi8vIDpzaG93IHN0YXJ0CmZ1bmMgZmlsdGVyRXZlblZhbHVlcyhhIFtdaW50KSBbXWludCB7Cgl2YXIgcmVzIFtdaW50Cglmb3IgXywgZWwgOj0gcmFuZ2UgYSB7CgkJaWYgZWwlMiA9PSAwIHsKCQkJY29udGludWUKCQl9CgkJcmVzID0gYXBwZW5kKHJlcywgZWwpCgl9CglyZXR1cm4gcmVzCn0KCi8vIDpzaG93IGVuZAoKZnVuYyBtYWluKCkgewoJLy8gOnNob3cgc3RhcnQKCWEgOj0gW11pbnR7MSwgMiwgMywgNH0KCXJlcyA6PSBmaWx0ZXJFdmVuVmFsdWVzKGEpCglmbXQuUHJpbnRmKCIlI3ZcbiIsIHJlcykKCS8vIDpzaG93IGVuZAp9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main

import "fmt"

// :show start
func filterEvenValues(a []int) []int {
	var res []int
	for _, el := range a {
		if el%2 == 0 {
			continue
		}
		res = append(res, el)
	}
	return res
}

// :show end

func main() {
	// :show start
	a := []int{1, 2, 3, 4}
	res := filterEvenValues(a)
	fmt.Printf("%#v\n", res)
	// :show end
}