I don’t think you need two, nested for loops for this.

Reply to this note

Please Login to reply.

Discussion

I could have done it with only one you reckon?

Yee. There are some programming problems (like sorting) where one would need to nest loops, but this problem can be solved with just one loop. What do you think?

Give it a try!

I'll go back at it, less code is better code for sure.

Thanks for the encouragement !

You can do it! 💪

Put 2 parameters in the first loop?

Backing up a second, I need some clarification. Will addFibs() be called more than once? Or will it be called only once?

Called once, with the numberOfFibs parameter specifing how many iterations of the first for loop.

OK, in that case, what happens if you just delete the outer for-loop? That is, what if you start right off with the of statement for length===0?

Oh yeah I see that now ! The step by step procedure I was sticking to got in my own way! Yeah , that code is utterly redundant.

💪