You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
925 B

6 years ago
## any
6 years ago
### Instructions
Write a function `Any` that returns `true`, for a `string` slice :
- if, when that `string` slice is passed through an `f` function, at least one element returns `true`.
6 years ago
### Expected function
```go
func Any(f func(string) bool, a []string) bool {
5 years ago
}
```
6 years ago
### Usage
Here is a possible program to test your function :
```go
package main
import (
"fmt"
"piscine"
)
func main() {
a1 := []string{"Hello", "how", "are", "you"}
a2 := []string{"This", "is", "4", "you"}
result1 := piscine.Any(piscine.IsNumeric, a1)
result2 := piscine.Any(piscine.IsNumeric, a2)
fmt.Println(result1)
fmt.Println(result2)
}
```
And its output :
```console
$ go run .
false
true
$
```
### Notions
- [Function literals](https://golang.org/ref/spec#Function_literals)
- [Function declaration](https://golang.org/ref/spec#Function_declarations)
- [Function types](https://golang.org/ref/spec#Function_types)