From 554e887d3e86ed3a86a44239496b1166ef79df50 Mon Sep 17 00:00:00 2001 From: Jean Vicelli Date: Tue, 20 Feb 2024 13:37:05 +0000 Subject: [PATCH 1/2] change hardcoded vector update to a for loop --- src/references/exercise.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/references/exercise.rs b/src/references/exercise.rs index edaddc535b4..9033013fcfe 100644 --- a/src/references/exercise.rs +++ b/src/references/exercise.rs @@ -25,9 +25,10 @@ fn magnitude(vector: &[f64; 3]) -> f64 { /// Change the magnitude of the vector to 1.0 without changing its direction. fn normalize(vector: &mut [f64; 3]) { let mag = magnitude(vector); - vector[0] /= mag; - vector[1] /= mag; - vector[2] /= mag; + + for item in vector { + *item /= mag; + } } // ANCHOR: main From ce059367d178a9e521668b18880e004132b6ef08 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Tue, 20 Feb 2024 17:16:33 +0100 Subject: [PATCH 2/2] Apply suggestions from code review --- src/references/exercise.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/references/exercise.rs b/src/references/exercise.rs index 9033013fcfe..122959a25bc 100644 --- a/src/references/exercise.rs +++ b/src/references/exercise.rs @@ -25,7 +25,6 @@ fn magnitude(vector: &[f64; 3]) -> f64 { /// Change the magnitude of the vector to 1.0 without changing its direction. fn normalize(vector: &mut [f64; 3]) { let mag = magnitude(vector); - for item in vector { *item /= mag; }