Last active
June 5, 2020 04:51
-
-
Save kjk/0bd6cd3d4b2b20e9ebad85009c1a3f80 to your computer and use it in GitHub Desktop.
example for https://notion.so/d7afa1154b434d1d802669cd92c1f6cf (made with https://codeeval.dev)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// :glot | |
package main | |
import "fmt" | |
// :show start | |
func filterEvenValuesInPlace(a []int) []int { | |
// create a zero-length slice with the same underlying array | |
res := a[:0] | |
for _, v := range a { | |
if v%2 == 0 { | |
// collect only wanted values | |
res = append(res, v) | |
} | |
} | |
return res | |
} | |
func main() { | |
a := []int{1, 2, 3, 4} | |
res := filterEvenValuesInPlace(a) | |
fmt.Printf("%#v\n", res) | |
} | |
// :show end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment