I typically have two cats at my desk: O’Malley lounging beneath it and Sandy perched on top. Today, however, both decided to engage in a swatting match. In the midst of their swiping (Swiper, no swiping!), Sandy accidentally knocked over my full cup of coffee, sending it splattering across my desk. I quickly dashed to grab paper towels and disinfecting wipes, then returned to clean up the mess. I had to clear everything off my desk, and my Kindle took the brunt of the spill. Thankfully, it still functions properly. It was complete chaos, and now both cats are keeping their distance from me since I shooed them away during the incident.
That was definitely the highlight of my morning. I went to the post office and finally mailed off the medical insurance papers. It only cost me a dollar to send them, but I wish I could have used cash instead of my card.
Later, I helped Karissa add a printer to her computer so that she could print documents. Unfortunately, the printout didn’t turn out as expected. I’m currently printing something to ensure the printer is functioning properly.
It seems the printout wasn’t quite right. Although the black ink isn’t empty, it wasn’t utilizing it. I’ve started a cleaning cycle for the printer in hopes that this resolves the issue. I should also check the printer settings, as I had to adjust the paper size earlier for printing. Printers can be quite frustrating to troubleshoot.
Fortunately, the cleaning did the trick, and the printer appears to be working well again. I reprinted some documents to verify its performance, and I’m pleased to say it seems to be functioning properly now.
I’m about to have some lunch. Kel suggested I could enjoy some grapes and cheese, though I’m uncertain if that truly qualifies as lunch—it’s certainly an improvement over the toast I sometimes opt for. I’ll make myself a sandwich and have some grapes on the side.
As for coding today, I need to write a function that checks if a string contains a substring. The phrasing of the problem is a bit confusing at the moment, so I think I’ll Google it for more clarity and return shortly.
Alright, it looks like we’ll be using the includes() method. The includes() method for Array instances checks whether an array contains a specific value among its entries, returning true or false as appropriate. Therefore, the code will look like this:
function containsSubstring(str, sub) { return str.includes(sub); }
Console.log looks like this:
console.log(containsSubstring("hello world", "world")); // true console.log(containsSubstring("JavaScript", "script")); // false (case-sensitive) console.log(containsSubstring("coding is fun", "fun")); // true
The next problem is that we need to write a function that counts how many times a character appears in a string. The console.log looks like this:
console.log(countChar("banana", "a")); // 3 console.log(countChar("hello", "l")); // 2
So obviously the skeleton of the code is:
function countChar(str, char) { // Code here }
So we can use the split() method. The .split(char) method splits the string at each occurrence of char and returns an array. The number of times char appears is array.length – 1.
function countChar(str, char) { return str.split(char).length -1; }
I need to write a function that returns an array of even numbers. Unfortunately, I neglected to clean the screen of my monitor after the coffee fiasco, and the spots are quite distracting. I should take a moment to clean the screen before I continue.
That’s much better. For this task, we will utilize the filter() method. The filter() method on Array instances creates a shallow copy of a portion of the given array, retaining only the elements that pass the test implemented by the provided function. Essentially, it will iterate over the array and determine which numbers are even.
function findEven(arr) { return arr.filter(num => num % 2 === 0); }
- The function takes an array arr as input.
- It uses the .filter() method to iterate over the array and check if each number is even.
- A number is even if num % 2 === 0.
- The function returns a new array containing only the even numbers.
I need to write a function that returns the index of a target in an array, or -1 if not found. Hmm, I don’t know why they can’t word these better. With some Googling, I found the findIndex() method. The findIndex() method of Array instances returns the index of the first element in an array that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned. That sounds easy enough.
function findIndex(arr, target) { return arr.findIndex(num => num === target); }
- .findIndex() searches the array and returns the index of the first element that matches the condition.
- If the target is found, it returns the index.
- If the target is not found, it returns -1.
This next one confuses me. Write a function that converts an object into an array of [key, value] pairs. I’m going to have to Google this.
Today is Alex’s birthday, and he has just turned 20. It’s crazy how quickly they’re all growing up. I first met Alex when he was just 9 years old, which means I’ve been living here for 11 years now.
At the moment, I’m procrastinating on my coding because I’m struggling with a problem that’s got me confused. Lol. Time to do a little Googling! It’s such a relief to have Google available now. Can you imagine having it while you were in school? Still, I appreciate that I didn’t have Google when I was younger; I really enjoyed visiting the library and reading. /sigh. More procrastination ahead.
Did you know that if you search for “Google in 1998,” you’ll find the classic Google homepage? Interestingly, to maintain its lawns, Google opts to rent goats instead of using traditional lawnmowers. Back in 1993, the first web browser, Mosaic, made the internet much more user-friendly. I recall using AOL (America Online), and I believe my username was Timon0202, inspired by The Lion King. I can’t quite remember what my email address was, but I don’t think it was my username; it was likely something different.
Ok, some Googling, I came up with something about the coding problem. The Object.entries() static method returns an array of a given object’s own enumerable string-keyed property key-value pairs. So, I’m thinking I need to use this. The console.log looks like this:
console.log(objectToArray({ a: 1, b: 2, c: 3 })); // [["a", 1], ["b", 2], ["c", 3]]
So the skeleton of the code has to look like this:
function objectToArray(obj) { // Code here }
I think I have it:
function objectToArray(obj) { return Object.entries(obj); }
It’s fascinating to consider how my mind navigates through so many loops and leaps just to come up with a single line of code. One measely little line. I’m going to prepare myself a matcha latte now. For dinner, we’re having tacos, and I started the beans in the slow cooker this morning. I also need to tackle Lexi’s taxes since she left me her tax documents. I promise I will get to her taxes one day—hopefully soon.





