From 4e0598f9fb1a258a9859f080b784473057a0c526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Tj=C3=A4der?= <henrik@tjaders.com> Date: Sun, 5 Nov 2017 23:06:38 +0100 Subject: [PATCH] Implemented getting the last from the HashMap --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index baf03c4..55119f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,10 +39,24 @@ fn main() { Ordering::Greater => println!("Too big!"), Ordering::Equal => { println!("You win!"); + println!("Total number of attempts: {}", tries_counter); - for x in attempt_history { + for x in &attempt_history { println!("{:?}", x); } + + + println!("Getting the three last entries backwards from the HashMap.\n"); + println!("Attempt:Value"); + + for x in 0..3 { + if let Some(value) = attempt_history.get(&(tries_counter - x)) { + println!("{} : {}", tries_counter - x, value); + } else { + // Do nothing in case of error + } + } + println!( "Since the HashMap does not push things onto a heap like the Vec-type does, it will iterate over and print in the order items are found" -- GitLab