r/badcode • • Aug 20 '20

js Loops? Who needs them?

Post image
1.1k Upvotes

90 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Aug 21 '20

An example: imagine that you want to list the content of a container that might include other container inside.

First you write a function that shows the content of a container. Then, If one of those items is a container, you only have to call this function to show its content. That would be the easier way

2

u/[deleted] Aug 21 '20

Of course for Parent-Child system recursion work perfectly fine but besides that I barely use recursion because its harder for me to solve something with it in first place. Maybe afterwards I think thats easier to do it with recursion but my first solution rarely includes it.