🌊 Baby Know Recursion!
Tags: beginners, javascript, firstyearincode, computerscience
Published: 2020-05-11 07:04:20


**Note:** This blog is not professional in any way; it's just for laughs! (mostly mine)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/5jlhk3ttt9a9x095oewr.png)

Alright! a little bitty "Paper, Rock, Scissors" recursion toy problem, and I am ready for it. Let's break it down. You have **n** number of rounds, so let's make a loop for **n**, then send the possible throw into recursion.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a0w0iqlrb91as7bvhjah.gif)

**Dawg Gone it** why is my recursive code not working? You use recursion on the next round, then try to do an array concatenate, use a spread operator here, how many loops should I put, wait...

No...
Oh no...
Can it be...
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pnt1ux7z55dyb1si83rl.png)
But I thought I was the recursion master!
Maybe my head is not 100% today; ok, forget recursion. 
**Leonidas didn't have "recursion" when he died fighting for Sparta!**
I can do this with... 
FOR LOOPS AND CONDITIONALS
LOTS AND LOTS OF FOR LOOPS AND CONDITIONALS 
**Let's get this code crackalackin!**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3fsivz1p38e75ygjxka3.gif)

When they see my code, they will say:
**GOOD GOD, what determination! So many loops!** 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7h5m2leco8ce94evgvt5.png)



**Holy Mathematicians of the past!** It is just paper rock scissors! 
   Why is this taking so many loops!

Let me stop and think.

Ok, what advice did I hear one of my instructors tell me many years ago (**2 weeks ago**), if you hit a code wall: try to draw out the problem and visualize it. 

And that is just what I did; I left my computer desk and hid in the corner, playing paper rock scissors with myself; my family looked on and thought I lost my mind.

If we want to use recursion and build an array the same length as the rounds given to us, maybe I should send the **type** of throw as the recursive variable.
 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/80uwqk2f5rvi36hvi24h.gif)

But you would also want to **continue** with the original code run. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/160zgfgk67abek342ve8.gif)

And in the forEach, you can use concat or a spread operator to account for the multiple arrays... **GOT IT**


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ovgk8uydw753qacmmjia.png)

I'm back on track! Call DeepMind and tell them I'll be able to start in August. **Together, we will create an AI that will put us all in matrix chambers**. No problem is too big and...
   
what is that in the distance approaching the city? **Dear Keanu Reeves**, it is massive! We are all doomed; it is the mother-ship of junior level recursion problems.
It is...
n-queens... 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jmwp9e6dcdrzqarfemi9.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ed87o9pvm68r4x1v6hza.png)
So we are going from paper rock scissors to chess? For real? 

Well, this is starting to look like a bigger version of the paper rock scissors problem.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3jlhr2aid9kmow3ysoz6.gif)

 So we want to go down an entire length of column height. And send a recursive call at each index to check the next row for solutions while **continuing** on with our original code. That's the trick! Use recursion but don't stop with just one iteration!


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mswfcisyahpak8mv11co.png)

**Thanks for reading. I hope it made you smile!**

Stay focused || love your code