public/subjects/name_initials/README.md

40 lines
865 B
Markdown
Raw Permalink Normal View History

## name_initials
### Instructions
2022-05-23 08:39:40 +00:00
Create a **function** named `initials`. This function will receive a vector of string literals with names, and return a vector of Strings with the initials of each name.
2022-05-23 17:32:53 +00:00
### Expected Functions
```rust
pub fn initials(names: Vec<&str>) -> Vec<String> {
}
```
2022-05-23 08:39:40 +00:00
> Your heap allocations will be monitored to ensure that you do not make too many allocations, and that your allocations are reasonably sized.
### Usage
2021-02-08 17:51:44 +00:00
Here is a program to test your function:
```rust
use name_initials::initials;
fn main() {
2021-02-17 06:55:41 +00:00
let names = vec!["Harry Potter", "Someone Else", "J. L.", "Barack Obama"];
println!("{:?}", initials(names));
}
```
And its output
```console
$ cargo run
["H. P.", "S. E.", "J. L.", "B. O."]
$
```
### Notions
- [stack and heap](https://doc.rust-lang.org/1.22.0/book/first-edition/the-stack-and-the-heap.html)