Week 5 Day 4 – Callbacks Are Hard.
Another day of JavaScript, and the syntax is getting easier and easier to grasp. My biggest issue yesterday was just intimately understanding callbacks. Everyone keeps telling me that they’re basically equivalent to Ruby’s blocks. I get that, I can totally see it when I’m shown an easy one-liner example. But when it gets into the more complicated, I start to lose sight of this “template” of how I usually see callbacks.
One of the coolest problems though, that’s kind of helping me understand callbacks a little bit more was an absolutely absurd version of bubble sort. Ironically enough, they called the problem absurdBubbleSort
. In the problem, instead of having the function sort the pairs of numbers, the user is prompted to analyze whether or not the first number is greater than the second number within the terminal. If the answer was yes, a true was passed into a callback, which would then continue to perform the swap function within that callback. Once that was completed, a recursive call to the function would happen, thus repeating the cycle until one full cycle returned false to the callback every single check.
My pair and I were stuck on this for a good while. And we were stuck because we weren’t passing the callback in correctly, invoking the recursive recursive call in the right spot, or closing the user input event at the right time. All these issues lead to a very complicated problem, but once we figured it out, it was smooth sailing.
After the bubble sort, we dove right into Towers of Hanoi with maybe… 20 minutes left? We only managed to finish like 3 functions before time was up. It was fun though! Like I said yesterday, it’s really awesome to take old concepts and problems, and solve them with our new language. Today’s topic is on arguments and prototypical inheritance, finishing it off with building an Asteroid game. I’m really hoping that we get to the asteroid game.
Until tomorrow, take care guys!