mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-06-15 00:04:58 +02:00
iterators1 solution
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
// When performing operations on elements within a collection, iterators are
|
||||
// essential. This module helps you get familiar with the structure of using an
|
||||
// iterator and how to go through elements within an iterable collection.
|
||||
//
|
||||
// Make me compile by filling in the `???`s
|
||||
|
||||
fn main() {
|
||||
// You can optionally experiment here.
|
||||
@ -10,19 +8,18 @@ fn main() {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn iterators() {
|
||||
let my_fav_fruits = vec!["banana", "custard apple", "avocado", "peach", "raspberry"];
|
||||
let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"];
|
||||
|
||||
let mut my_iterable_fav_fruits = ???; // TODO: Step 1
|
||||
// TODO: Create an iterator over the array.
|
||||
let mut fav_fruits_iterator = ???;
|
||||
|
||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"banana"));
|
||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 2
|
||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"avocado"));
|
||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 3
|
||||
assert_eq!(my_iterable_fav_fruits.next(), Some(&"raspberry"));
|
||||
assert_eq!(my_iterable_fav_fruits.next(), ???); // TODO: Step 4
|
||||
assert_eq!(fav_fruits_iterator.next(), Some(&"banana"));
|
||||
assert_eq!(fav_fruits_iterator.next(), ???); // TODO: Replace `???`
|
||||
assert_eq!(fav_fruits_iterator.next(), Some(&"avocado"));
|
||||
assert_eq!(fav_fruits_iterator.next(), ???); // TODO: Replace `???`
|
||||
assert_eq!(fav_fruits_iterator.next(), Some(&"raspberry"));
|
||||
assert_eq!(fav_fruits_iterator.next(), ???); // TODO: Replace `???`
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user