forked from root/public
hamza
2 years ago
committed by
David Mata
1 changed files with 38 additions and 0 deletions
@ -0,0 +1,38 @@ |
|||||||
|
## count-negative |
||||||
|
|
||||||
|
### Instructions |
||||||
|
|
||||||
|
Write a function that takes an array of integers and returns the number of negative numbers in the array. |
||||||
|
- If the array is empty, the function should return `0`. |
||||||
|
|
||||||
|
### Expected function |
||||||
|
```go |
||||||
|
func CountNegative(numbers []int) int { |
||||||
|
// your code here |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
### Usage |
||||||
|
|
||||||
|
```go |
||||||
|
package main |
||||||
|
|
||||||
|
import "fmt" |
||||||
|
|
||||||
|
func main(){ |
||||||
|
fmt.Println(CountNegative([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})) |
||||||
|
fmt.Println(CountNegative([]int{-1, -2, -3, -4, -5, -6, -7, -8, -9, -10})) |
||||||
|
fmt.Println(CountNegative([]int{})) |
||||||
|
fmt.Println(CountNegative([]int{-1,2,0,-3})) |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
and the output should be: |
||||||
|
|
||||||
|
```console |
||||||
|
$ go run . |
||||||
|
0 |
||||||
|
10 |
||||||
|
0 |
||||||
|
2 |
||||||
|
``` |
Loading…
Reference in new issue