Tommy is feeling better, so he went to work today. I had my doctor’s appointment, during which we reviewed my lab results and I underwent a physical examination. I’m pleased to report that my lab results were good, and the physical went well. Additionally, I’ve lost three pounds since my last visit. I’m happy about that, as I’ve been working towards my goal of losing 20 pounds. The doctor has discontinued my blood pressure medication. Today, my blood pressure was low, and she had already reduced my dosage by half. This is encouraging news. She emphasized that achieving my weight loss goals would be beneficial. When I inquired about the possibility of using a diet pill or Ozempic, she explained that she wants to see me focus on exercising first before considering any medication.
It snowed last Saturday, but this Saturday, the temperatures are expected to reach the 80s, which is fantastic news! Hopefully, that means we can start working on my desk again, and I’d love to have it set up for use. With the warmup, it’s probably time to clean out the pellet stove and unplug it for the season, as it seems unlikely that we’ll experience any more cold weather if temperatures rise that much. Well, maybe. Being at such a high elevation, our weather tends to be more extreme than it is down in the city.
I visited the post office this morning to mail Karissa’s official transcript to the university. She will be attending the same one as Alexis, but Karissa has decided to pursue her studies online. Initially, she considered going to a university in the city, but we couldn’t find a major there that aligned with her interests. The university Alexis attends offers a major that closely matches what Karissa studied in community college.
I still need to set up my planner for the week. I intended to do it yesterday but didn’t get around to it. Today, I’m struggling to focus on coding since I started later in the day. After my appointment and going to the post office, followed by lunch, I began coding just before 1 p.m., but I’m having a hard time staying on task. I found myself looking at Facebook Messenger because our group chat has been quite active, and then I got sidetracked scrolling through Facebook instead of concentrating on my coding.
Coding today I’m trying to focus on how to write a function in JavaScript that takes a deeply nested array (i.e., an array that contains arrays within arrays) and returns a flat array with all the elements at the same level. We are going to do the reduce() method for this function. Then I will use the .flat(Infinity) method at the end.
function flatten(arr) { return arr.reduce((acc, item) => { return acc.concat(Array.isArray(item) ? flatten(item) : item); }, []); }
Key Concepts:
- Array.prototype.reduce() is used to accumulate a result (in this case, a flattened array).
- Array.isArray(item) checks if the current item is an array.
- concat() merges arrays or values into one array.
Now we can also use the .flat(Infinity) method, which is a lot easier. I will use an arrow function.
const flatten = arr => arr.flat(Infinity);
.flat() is a built-in array method introduced in ES2019 (ES10). It flattens nested arrays up to a specified depth. Passing Infinity tells JavaScript:
“Keep flattening until there’s nothing left to flatten, no matter how deeply nested.”
- arr => is an arrow function (a short way to write a function).
- arr.flat(Infinity) flattens the whole array no matter how deep it is.
- It’s stored in a constant named flatten.
We’re having leftovers for dinner tonight. Last night, we had pulled pork sandwiches, so we’ll be having those again, accompanied by some vegetables. I’m not sure which veggies we’ll have since Kel is picking them up later today, but I believe brussels sprouts are on the menu. That sounds cool. I’m starting to feel hungry. I have only had a sandwich for lunch today.





