Post/Code

HomeAboutUsesNow

Improvement.

Today I needed to skip Daily Coding Problem 3 and moved onto problem 4 because:

  1. I first need to learn more about binary trees before attempting problem #3.
  2. The problem is not presented in JavaScript, so I will need to understand the code better before attempting problem #3.

Problem #4.

As a result, I proceeded to #4 and managed to finish this problem in 38 mins, which is certainly an improvement! Regardless of time, what improved was my approach to the problem. I was very conscious of doing the following in my implementation:

  1. Slow down, think/talk the problem through first to make sure you understand it. (Illustrate your understanding of the problem)
  2. Write tests of the examples first, then add a few extra tests based on your understanding of the problem. (Confirm that you understand the problem)
  3. Write out your solution in comments/psuedo code before writing actual code to try and get a better grasp of the nature of the problem. (Illustrate how you plan to solve the problem)
  4. Write the code in baby steps, make sure you get the obvious results first. (Show how you actually break things down)
  5. Break the steps into separate functions if you need to. (Show that you are able to think atomically and evolve your thinking as you go)

While this problem was likely easier than #3, it was more or less on par with #1 and #2 so I feel that I have certainly learned something through this process so far.

Note: I have had to refer to MDN at times, which I would not be able to do in a real test situation. Today, I revisited .sort. I have used .sort before, but I needed to refer to the docs to refresh my memory.

Essentially, .sort takes a callback function which you use to compare items to each other. Sort will convert to string and you need to evaluate whether one is before or after the other. That is to say:

  • Return 1 if a comes before b
  • Return -1 if a comes after b
  • Return 0 if a and b are equal

Solution here.