Day 100: The Event Loop, Plus Hash Tables

Usually I’m a little tired and want to take a break after day 100 but this time I can’t wait to jump back in with some actual JavaScript projects. I have learned a lot of technical knowledge this past round. Now it’s time to start building stuff again. This is going to be fun.

TLDR;

Okay, so here are the highlights of what I did:

  • Data structures -> Continued going through a freeCodeCamp YouTube video covering data structures for beginners. I covered the section on Dictionaries. The concept is not new to me but the use of Hash tables is a bit intimidating. I definitely need to implement this to become less scared of it.
  • JavaScript -> Finished reading through chapter 15 of “Eloquent JavaScript” by Marijn Haverbeke. The last few sections of the chapter covered different types of events and timers. It was great to see debouncer functions again and not freak out. LOL

Debouncing

<textarea>Type something here...</textarea>
<script>
  let textarea = document.querySelector("textarea");
  let timeout;
  textarea.addEventListener("input", () => {
    clearTimeout(timeout);
    timeout = setTimeout(() => console.log("Typed!"), 500);
  });
</script>

Giving an undefined value to clearTimeout or calling it on a timeout that has already fired has no effect.

We can use a slightly different pattern if we want to space responses so that they’re separated by at least a certain length of time but want to fire them during a series of events, not just afterward.

<script>
  let scheduled = null;
  window.addEventListener("mousemove", event => {
    if (!scheduled) {
      setTimeout(() => {
        document.body.textContent =
          `Mouse at ${scheduled.pageX}, ${scheduled.pageY}`;
        scheduled = null;
      }, 250);
    }
    scheduled = event;
  });
</script>


Goal For Round 6 of the #100DaysofCode Challenge

This is my sixth round of the “#100daysofcode” challenge. I will be continuing my work from round five into round six. I am currently working through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. My goal is to become more familiar with algorithms and data structures. This goal was derived from my goal to better understand operating systems and key programs that I use in the terminal regularly e.g. Git. This goal was in term derived from my desire to better understand the fundamental tools used for coding outside of popular GUIs. This in turn was derived from my desire to be a better back-end developer.

I have no idea if my path is correct but I am walking down this road anyways. Worst case scenario I learn a whole bunch of stuff that will help me out on my own personal projects.