I am having trouble figuring out where to even start with figuring out the minimum value in an array using an if statement. Part of me feels like this should be easy, and the other part feels like my brain is looping into oblivion over this problem. Has anyone figured this out to the point that they may be able to hint around at what I’m missing? In the meantime, I just be over here talking to myself and trying stuff out.
"Create a function with an array of numbers as its parameter. The function should iterate through the array and return the minimum value from the array.
Hint: Use what you know about
if statements to identify and store the smallest value within the array."
What they are trying to hint at is a need for a recursion which have if/else statements in there or a loop with a nested if statement.
I built mine 2 ways (as you’ll have to do for the exercise): 1 is a for loop + Math method I already knew & the other is if/else using recursion.
There are multiple ways to go about this - you’ll get their answer in part B. They went with a for loop with a nested if statement.
Thanks… I thought the same about recursion, but I definitely needed to go back and review those sections to understand it better. I had also looked up the Math functions and was worried I was getting off track. Thanks for the reassurance. I was also getting ahead of myself and trying to do everything in the first section, not realizing it was actually split up.
I ended up solving the whole thing in 1 go too - didn’t do a 2 step process. Then went back in & split it up.