My focus just wasn’t here today. I did a little coding today, paid some bills and laundry.
My mind keeps replaying yesterday’s drama. I’m glad I was there to take control of the truck. I’m ok, and so is Tom and Karissa. But I was scared. I didn’t know what was going on with Tommy at the time and didn’t know if he could take control of the truck again. I’m glad everything turned out ok. I talked to Karissa as well and told her next time to not undo her seatbelt if something were to happen.
I still can’t drive my car. Normally I don’t care to drive anywhere and I have nowhere to go. But now I miss having my car just in case I wanted to go to the store or something. Alexis has a package at the post office that I need to get. And my medication is ready at Walmart and for some reason they are saying it’s $2,000. So I need to go and find out what the heck is up with that cause I’m not paying that. And why would the medication be that much to begin with?
I’m not sure what is for dinner. I can’t go drive to the store to get anything. I feel kind of useless without a car. I’m going to watch some YouTube videos until I can be useful again…
——————————————
Recursion is the concept that a function can be expressed in terms of itself. To help understand this, start by thinking about the following task: multiply the first n elements of an array to create the product of those elements. Using a for loop, you could do this:
function multiply(arr, n) { let product = 1; for (let i = 0; i < n; i++) { product *= arr[i]; } return product; }
However, notice that multiply(arr, n) == multiply(arr, n - 1) * arr[n - 1]. That means you can rewrite multiply in terms of itself and never need to use a loop.
function multiply(arr, n) { if (n <= 0) { return 1; } else { return multiply(arr, n - 1) * arr[n - 1]; } }
The recursive version of multiply breaks down like this. In the base case, where n <= 0, it returns 1. For larger values of n, it calls itself, but with n - 1. That function call is evaluated in the same way, calling multiply again until n <= 0. At this point, all the functions can return and the original multiply returns the answer.