Post/Code

HomeAboutUsesNow

Mo' Coding Problems Refactored.

After the relative failures in my coding problem yesterday - I decided to attempt the "Possible Improvements" suggested. Having understood the problem, it easy to refactor the solutions using more modern ES6 constructs such as .filter, .reduce and .map.

Lessons Learned.

  1. Once you have a solution, it becomes easier to reason about improvements if you have an idea of what avenues you have for improvement.
  2. Tests really help you find bugs in your code! (During the refactor, after my first pass I thought I had a successful refactor, but a failing test showed me that I had a flaw in my reasoning!)
  3. It helps to step through your failing code step by step to understand where and why you are going wrong!
  4. You cannot use a conditional inside of .reduce, you first need to .filter your set on the condition you have in mind and then .reduce from there.

Possible Improvement.

Combine the two functions into a more succinct solution.

All things considered, I still feel a long way off from being half-way decent at algorithms, but I am making progress, no matter how small the steps!