I’m trying to separate the input arrays to then extract the largest number from each one and put them into a new array. That’s my plan, but I’m not going about it correctly obviously.
first review what return does please, and what to expect if you use it inside a loop
like, what is returned by the function in a case like the below?
function sum() {
let sum = 0;
for (let i = 0; i < 10; i++) {
sum += i;
return i;
}
return sum;
}
console.log(sum());
Hi @jfo0707
Perhaps take a short break - you’ll get some rest, but your mind will keep processing the information in the background.
Then take a step back, and write down in words what you want the function to do. Don’t worry about syntax at this point. This is called pseudo code.
After that, identify what methods you can use, and any skill or knowledge gaps. Once you have a plan, then start writing the code / researching ways you can code.
I think most programmers have gone through the process of spending time writing code, instead of starting with a plan, as doing something feels more productive than documenting it first.
Happy coding
Thank you Teller. I’ll do just that. I agree I can come back with a fresh perspective and start by writing out a plan.
Finally finished it! I was laying down thinking about it and I knew a nested loop should get me to where I was trying to go. But, I had to know when to push the highest numbers and when to return the result. Thanks all who chipped in to help me figure this out. I’m accumulating a pretty good notebook as I go through these challenges.
I would really start with a plan first instead of some syntax (a nested loop)
Hi - I’ve been reading this post and I’m very curious @jfo0707, did you get the task completed? I really liked your idea of sorting the array 1st and popping off the last element into a new array all with 1 loop.
Chris.