There's just so many ways to do loops. for
loops, while
loops, recursive
function calls, and a plethora of Array.prototype
functions.
In this repo you will find examples of overthinking a stupid simple problem. If you don't learn anything new, at least have some fun!
There's a verry hungry caterpillar π sitting in a basket of fruits. As any other caterpillar would do, he starts eating them.
At some point, he will get full and if attempting to eat more, he will die (throw an error).
You have to feed the caterpillar fruits from the basket, and make sure not to let him eat to much!
PS: The caterpillar is picky and doesn't like π.
Most of the time, we use loops when working with arrays. But iteration doesn't have to be restricted to arrays: you can iterate on iterator objects, which you can create with a generator function.
I bet that there are plenty more ways to overthink loops, but for now in this repository we will play with these two:
You can find each in its folder β¨
Inspired from reading the story of the very hungry caterpillar from Eric Carle with my toddler πΆπ».