I’m feeling quite sleepy today. I took a 15-minute nap, which may not seem substantial, but it truly helps. My sleep doctor advised me on this. Taking a long nap can leave you feeling groggy afterward, but a brief 15-minute nap can effectively boost alertness, especially in the afternoon, without the risk of grogginess or disrupting nighttime sleep.
I had a doctor’s appointment this morning, which went well. She examined my ear, confirmed there is an infection, and prescribed antibiotic ear drops. My ear drops are ready for pick-up at Walmart, and I also need to collect some medicine for Karissa while I’m there.
Tomorrow, Tommy has a day off and a couple of dentist appointments scheduled—yes, two in one day. I’m not quite sure what led him to make that choice, as that’s quite a lot for one day’s worth of dental work. I understand he wants to tackle everything at once, but it seems like a lot to put his mouth through! Additionally, we’ll be taking Karissa with us so she can get her new glasses.
At some point, we also need to take her to the college to pick up her stole for graduation. Both girls are set to graduate in May, with Karissa’s ceremony on the 3rd and Alexis’s on the 10th. I haven’t fully processed the fact that they are graduating yet. I feel excited but also a bit emotional about it.
Today is relatively uneventful. I’m currently coding—well, I was coding before I started writing this. Now, I need to focus on implementing the Array.prototype.map method. Here’s what I have so far:
function customMap(arr, callback) { // Check if arr is an array if (!Array.isArray(arr)) { throw new TypeError("First argument must be an array"); } // Check if callback is a function if (typeof callback !== "function") { throw new TypeError("Second argument must be a function"); } }
Breaking this down:
!Array.isArray(arr)
- The ! (logical NOT) operator negates the result.
- If arr is not an array, this condition becomes true, and the code inside the if block runs.
throw new TypeError(“First argument must be an array”);
- If arr is not an array, the function throws a TypeError.
- This stops the function immediately and provides an error message.
- A TypeError is used because passing the wrong type (something other than an array) is a type-related issue.
typeof callback !== “function”
- typeof callback checks the type of the callback argument.
- If callback is not a function, the condition becomes true.
throw new TypeError(“Second argument must be a function”);
- If the condition is true, this line throws an error.
- TypeError is used because passing something that isn’t a function is a type-related mistake.
- The error message helps the user understand what went wrong.
Ok, after a few hours I think I have it:
function customMap(arr, callback) { // Check if arr is an array if (!Array.isArray(arr)) { throw new TypeError("First argument must be an array"); } // Check if callback is a function if (typeof callback !== "function") { throw new TypeError("Second argument must be a function"); } // Create a new array to store results let newArray = []; // Iterate over each element in the array for (let i = 0; i < arr.length; i++) { newArray.push(callback(arr[i], i, arr)); } // Return the new transformed array return newArray; }
Breaking this down:
// Create a new array to store results let newArray = [];
Purpose: Create an Empty Array
- newArray is initialized as an empty array [].
- This will store the transformed values after applying the callback function.
// Iterate over each element in the array for (let i = 0; i < arr.length; i++) {
Purpose: Loop Through the Input Array
- The for loop runs from i = 0 to i < arr.length, meaning it processes each element in arr one by one.
- i represents the index of the current element in the array.
newArray.push(callback(arr[i], i, arr));
Purpose: Apply the Callback Function to Each Element
callback(arr[i], i, arr) calls the function passed as the second argument (callback) on:
- arr[i] → the current element.
- i → the index of the current element.
- arr → the original array itself.
- The result of the callback function is pushed (.push()) into newArray.





