Check Element Exists in a Slice
·
237 words
·
2 minutes read
Go doesn’t have a find
or in_array
function as part of it’s standard library. They are easy to create however. In this example we create a Find()
function to search a slice of strings for the element we are looking for.
Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you will have to create different find functions for different types - as needed.
|
|