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.

46 lines
833 B

## searching
### Instructions
In this exercise you will have to complete the function `search`.
3 years ago
This **function** receives an array and a key of `i32`, then it will return the position
of the given key in the array.
3 years ago
Only arrays with uniques keys will be tested.
### Notions
3 years ago
- [patterns](https://doc.rust-lang.org/book/ch18-00-patterns.html)
### Expected functions
```rust
3 years ago
pub fn search(array: &[i32], key: i32) -> Option<usize> {
}
```
### Usage
Here is a program to test your function.
```rust
3 years ago
use searching::*;
fn main() {
let ar = [1, 3, 4, 6, 8, 9, 11];
let f = search(&ar, 6);
println!(
"the element 6 is in the position {:?} in the array {:?}",
f, ar
);
}
```
3 years ago
And its output:
```console
$ cargo run
the element 6 is in the position Some(3) in the array [1, 3, 4, 6, 8, 9, 11]
$
```