Skip to content

Commit

Permalink
Change hardcoded vector update to a for loop (#1833)
Browse files Browse the repository at this point in the history
iterating over the vector instead of hardcoding each item

---------

Co-authored-by: Martin Geisler <[email protected]>
  • Loading branch information
jcvicelli and mgeisler authored Feb 20, 2024
1 parent 8344cbc commit 9d63f23
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/references/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ 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
Expand Down

0 comments on commit 9d63f23

Please sign in to comment.