The weather needs to remain warm so I can work on my desk. This week, temperatures are in the 40s and 50s, but I’m hopeful that it will warm up more in April. I took a short nap this morning, just a few hours, since I had less than six hours of sleep last night. I’m feeling much better now that I’ve had some extra rest.
This weekend was quite relaxing. On Saturday, Tommy and I worked out and then went to Smith’s to pick up a few items for dinner. Initially, we planned to have fried rice for Alex’s birthday dinner, as he had chosen. However, with my appointment at Costco and Alex needing to go to work, we ran out of time. Instead, we opted for another meal: butter shrimp and broccoli, which Alex also selected. At 5 PM, I had my hearing aid appointment at Costco. It turned out that the receiver in my right hearing aid wasn’t functioning properly, so they replaced it. Now, both of my hearing aids are working well, and I’m thrilled to be able to hear clearly again!
On Sunday, Kel and I went to a friend’s house to play Bunco, and it was a lot of fun. I ended up with four buncos and four baby buncos. The game mostly relies on luck when it comes to scoring a bunco. While we were playing, Tommy watched a movie with a friend. Later, we returned home to prepare for Tommy’s hockey game. A few hours later, Tommy and I headed out for his game. By the end of hockey, Tommy was quite tired; he had worked out twice that day—once in the morning with weights and then, of course, during the hockey game.
I had breakfast for lunch today, enjoying eggs and toast. It was a quick meal and filled me up. I’m also having a Coke. The house is quiet, just Karissa and I here. I haven’t seen Sandy since this morning and I’m curious about where she went. She typically sleeps in the office, but I don’t see her here. I plan to look for her later. O’Malley is currently sleeping in the bedroom.
For coding, I’m figuring out how to write a function that rotates the array positions to the right. Why do they always word the problems all weird-like? Ok, the console.log looks like this:
console.log(rotateArray([1, 2, 3, 4, 5], 2)); // [4, 5, 1, 2, 3]
Given an array, we need to shift all element’s positions to the right.
Since we are rotating, the elements that go past the last position should wrap around to the beginning. Google mentions splice() and unshift() or slice() and concat(). The splice() method in JavaScript modifies an array by removing, replacing, or adding elements. It returns an array containing the removed elements, and it changes the original array directly. The unshift() method of Array instances adds the specified elements to the beginning of an array and returns the new length of the array. The slice() method returns selected elements in an array, as a new array. The concat() method in JavaScript is used to merge two or more arrays or strings, returning a new array or string without modifying the original ones. I think I will go with slice() and concat() since I’m more familiar with them.
The skeleton of the code looks like this:
function rotateArray(arr, k) { // Code here }
The ‘k’ tells us how many elements from the end should be moved to the front. It represents the number of positions we need to rotate the array to the right.
function rotateArray(arr, k) { let n = arr.length; k = k % n; // Ensures k is within array length and prevents redundant rotations return arr.slice(-k).concat(arr.slice(0, n-k)); }
- arr.slice(-k): Takes the last k elements (to move to the front).
- arr.slice(0, n – k): Takes the first part (which shifts right).
- .concat(…): Joins them together.
Now I need to write a function that removes all spaces from a string. I think there is a method I can use for this, but I forget what it is. Ok, the method is replace(). This method replaces all occurrences of spaces (or any matched pattern) with an empty string. We are going to use regular expressions too. Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. So let’s try this.
function removeSpaces(str) { return str.replace(/ /g, ""); // Removes all spaces and replaces with an empty string. Meaning we are replacing it with nothing }
This is the console.log, which works:
console.log(removeSpaces("hello world")); // "helloworld" console.log(removeSpaces(" Java Script ")); // "JavaScript"
This next topic is a bit confusing. I need to write a function that creates a deep copy of a nested object without using JSON.stringify(). I’m not entirely sure how to approach this. To clarify, JSON.stringify() is a built-in JavaScript function that converts a JavaScript object or array into a JSON-formatted string, but that explanation doesn’t offer much additional insight.
I plan to research this for a while and revisit it tomorrow. What is tomorrow? Oh, it’s Tuesday. I have blood work scheduled in the morning due to a doctor appointment next week. I hope the results come back well. I don’t mind the blood work; it tends to be a quick process. I do need to fast beforehand, which is why I opted to do this blood work in the morning.
I’m not sure what is for dinner. Maybe some beef and broccoli. And some rice? That does sound good. If anyone was wondering. Both O’Malley and Sandy were sleeping in the bedroom. Then Sandy moved to the living room.





