Recursion — A brief explainer

Recursion can be one of those topics that is either loved or hated. On the love side, recursion can save a ton of time and computational power. On the hate side, it is often hard to wrap your head around just how to solve a problem with recursion until it just clicks, usually after you’ve been whiteboarding and banging your head against the problem for some time. From my own experience with recursion, I certainly fall into the latter party. Recursion is a tool that I know can be extremely useful but it is certainly not the first tool I reach for unless I am doing something simple like a factorial.
Often when I do find it is time to attack a problem with recursion is when I am working with loops. Just in case you don’t work in programming a loop is just what it sounds like, a piece of code that executes repeatedly until a condition is met. When you find yourself using a loop to work through a problem, the concept of code repeating itself in order to solve a bigger problem is very similar to how recursion works, which is a function calling itself with updated information until a condition is met, then the result of each call of the function is passed back to the original call.
The following is my attempt to give a TL;DR for recursion explaining the very basics with a short code example of a recursion power function (x to the power y). I hope you enjoy it and please let me know what you think in the comments.