Flatiron Phase 1: Iteration

Phil Sheridan
4 min readDec 11, 2023

--

Phase 1 of Flatiron was an incredible journey for me, and I cannot wait to continue working through the next four phases. I loved the layout of this course. The workflow of using Canvas, GitHub and Visual Studio Code in tandem made the work feel real and extremely rewarding to complete. During Phase 1 I found myself falling slightly behind schedule due to the holidays and not having a device I could bring with me to get work done. I have recently picked up a Lenovo Slim 7 Pro to continue working on for the remained of the course and I am confident that this will help prevent any headaches I was running into previously. Working from two separate desktops (work and home), I found myself forgetting to commit my changes to GitHub and being stuck without my work. I found the material difficult but very well thought out and manageable. Any time I found myself getting stuck I was able to look back at previous modules or notes and eventually find my way. The hardest modules for me where the array methods. I fully understood the concept and function of these methods, however I needed to look up many examples of them online to figure out the best use cases.

I decided on a dictionary API for my Phase 1 project because I have a degree in Linguistics. I wanted to make an application that represented this side of my expertise. The free Dictionary API that I found made it easy to quickly draft some ideas. I knew I wanted to list every definition of the word, but quickly realized I would need a way to sort by part of speech because the API would return groups of results rather than one long list. This meant that verbs and adjectives were randomly thrown between nouns and prepositions. I also decided later on to add the ability to hide the lists of definitions by clicking the part of speech header because there were so many definitions for the words I was testing with. One of these words was “round” because it would return 6 different parts of speech, which was an excellent test for my grouping algorithm. I originally wanted to be able to view much more information about each word but found that the dictionary I was using didn’t have history/etymology for every word I was searching for. Rather than continuing with this idea, I decided to implement json-server to save a list of local favorites. Below is a .gif of the application using the word “test” as an example:

This allowed me to save words like “round” to make sure each added feature wasn’t causing issues with the sorting algorithm or other features added later on like the phonetic transcriptions. The transcriptions were also added later on in the project, though they were not too difficult to implement because the API made them readily available. The following is a snippet from my phase 1 project. In this snippet I am iterating through the data returned from my API. Comments are included to outline what each chunk of code is doing:

function reduceDefinitions (data) {
let reducedDefinitions = {};
//reduceDefinitions takes one Object (data). This variable is the result of the API fetch. Below is an example of this json data:
//https://api.dictionaryapi.dev/api/v2/entries/en/test
//The function returns reducedDefinitions (an object of parts of speech paired with cooresponding definitions).

data.forEach(function (fullGroup) {
//The API returns multiple results for each word (each result may have a mix of definitions of different parts of speech). This forEach statement
//itterates through each of these results. Each fullGroup is an Object containing 6 keys: license{}, meanings[{}, {}...], phonetic"",
//phonetics[{}, {}...], sourceUrls[], and word"".

fullGroup.meanings.forEach(function (outputGroup){
if (!Object.keys(reducedDefinitions).includes(outputGroup.partOfSpeech)) {
reducedDefinitions[outputGroup.partOfSpeech] = [];
};
//Each outputGroup is an array of objects (each object cooresponding to a part of speech) each containing n(definitions). The following if statement
//checks if the given part of speech is a key in reducedDefintions, then creates the key if not.

outputGroup.definitions.filter(function (definitionObject){
return reducedDefinitions[outputGroup.partOfSpeech].push(definitionObject)
//reducedDefinitions[part of speech] is then populated with the definitions matching that part of speech.
});
});
});
return reducedDefinitions;
};

This section was by far the most challenging aspect of this project. There were many iterations of this function (some of which functioned the same as the final product), however, to ensure that the code was easily understandable I wanted to replace many of the for…in statements with forEach() or filter() array methods. These methods allowed me to initialize variables within the callback function rather than standalone within the for..in statements.

fullGroup.meanings.forEach(function (outputGroup){...}

//rather than using:

for(let meanings in data[fullGroup].meanings) {
let outputGroups = data[fullGroup].meanings[meanings]; ...}

My biggest takeaway from this project was to always be iterating. As a linguistics student, I wrote dozens of essays to earn my degree, and found myself in a very comfortable space with my style of writing. Because of this, I developed a “bad” habit of writing an initial outline of my paper, then going full bore deep dive into writing one singular “perfect” draft. I was never a fan of resting on my ideas or going back and editing my work because I was sure that my thought process from the start would not change even after stepping away and refreshing my mind. This process does not translate to coding. I found myself re-reading and, re-writing my code over and over in this project to get certain parts of my application working. I would remove full chunks of code and re-write them only to find that my initial attempt was almost identical to the new version (almost being the keyword). Even when I thought I was completely finished with my project, after diving back in I found that there were a few lines I could mitigate, or a variable that wasn’t needed. I am amazed at how this project was able to refine my workflow and I cannot wait to keep moving forward.

--

--