Flatiron Phase 3 Module
In my past blog posts, I expressed how challenging I felt it was to learn and implement the content. Well, I will say that this phase was by far the most challenging compared to the others. Throughout this phase it took a lot of focus, repetition and most importantly. PATIENTS. I am excited to say, I made it through the struggle and have learned a lot! I will touch on the structuring and implementation of methods and the approach I took to better understand them!
The topic I spent the most time studying was Active Record Methods. At first I felt like writing these methods was going to be a breeze. In some cases, it was! The simple methods like returning an ordered list of instances or finding a single instance by a specified key didn’t take me long to figure out. Once I started getting into the more complex methods such as, finding the most popular instance of a class or using helper methods within other methods. That’s when I started to struggle.
This method was definitely very challenging to implement correctly. One of the most helpful skills I used to get through this was figuring out what my end result needed to be and then thinking about all of the individual steps/code it might take to get that end result.
Above is the helper method I used in the most popular method to help reach my end result. This method was initially used to find the number of books written for a specific genre. The cool part about some of these simple methods is they can be very useful in simplifying the code for the more complex method. If you look at the first snip it. You can see this helper method being implemented in the first line of code. The first line of code is responsible for finding the the total number of books in each genre and return them as an array stored in the books_total variable. My book_count method is being used to find the total number of books for each genre instance. The second line of code finds the index with the highest books_total and stores that index in the idx variable. The final line of code takes the entire array of genre instances and returns the genre that was found and stored in the idx variable.
Approaching these types of methods line by line and being very conscious about what each line will return and how that is going to get you closer to your desired end result is crucial. Once I started thinking about each method this way, solving them became much easier!