Reviewing JavaScript Concepts

Posted by Alex Zdatny on March 1, 2020

Throughout the past week, I’ve been working on some coding challenges as well as reviewing JavaScript concepts to prepare for technical interviews. It’s given me a lot of perspective on my problem solving and analytical skills. Recently I was given feedback on a project that I built utilizing the Angular framework. While there are several reactions that could have emerged from this, I took it as an incredible learning experience and decided to focus on finding different ways to improve as a software engineer. I remember creating a study guide to prepare some of my portfolio project assessments and after practicing writing block statements, callback functions, arrow functions, I realized that they were used pretty frequently throughout the code.

When you comprehend the importance of algorithms and data structures, you have a much better mindset on how to solve problems in any language or framework. It wasn’t that I didn’t understand the definition of these concepts, but rather how they should be used. One of my habits when I was learning to become a developer was trying to find the solution immediately instead of approaching the problem in small steps. I’ve referenced this a lot in my blog posts because it’s arguably the place where I’ve struggled the most in almost all of my assessments. Since there could many solutions to a problem, the main priority should not be the answer, but rather the logical approach and the steps that you take to reach a solution.

For example, if you wanted to display a list of usernames in your Ruby on Rails application, what would the first step be? First you would think about where the usernames would be stored as you would want to create a user migration and model that would include and validate the username attribute. A username is a string and attribute of a user. If there are existing users, make sure that the username is included for each one to prevent other errors. Once those are created, you want to consider where the list of usernames are being rendered. If the application has separate profiles for each user, logically the best route to display this information would be on the users index.

Since the Rails framework has an MVC Architecture, inside of the Users controller, make sure that the index action has @users set to User.all. This comes from the User Model where all of the attributes are validated. Since you’re not manipulating the user data, the each method to iterate the array of users comes to mind. Looping through the list of users gives you access to an attribute that’s attached to the user. Despite this seeming like a simple scenario, this type of logic can be applied to a variety of functions that are built. What needs to be accomplished to get this list to display, which route would render the list, and what method do I need to use to access the usernames. Even if you’re dealing with larger components, thinking about how to write the function in smaller steps and psuedo code can really help you improve.