Quick actions

cmd+k|ctrl+k

Navigation

Languages

Slices / Filter a slice / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:13:19Z

Updated

2019-03-26T10:13:19Z

package main

import "fmt"

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

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