1
0
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:
mo8it
2024-06-28 02:07:56 +02:00
parent 746cf6863d
commit cf9041c0e4
3 changed files with 36 additions and 27 deletions

View File

@ -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 `???`
}
}