<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ericeinerson</title>
    <description>The latest articles on DEV Community by ericeinerson (@ericeinerson).</description>
    <link>https://dev.to/ericeinerson</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F795078%2F8caf96e2-d373-4b59-a01b-eac8bb1fedfe.jpeg</url>
      <title>DEV Community: ericeinerson</title>
      <link>https://dev.to/ericeinerson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ericeinerson"/>
    <language>en</language>
    <item>
      <title>C# Dictionary</title>
      <dc:creator>ericeinerson</dc:creator>
      <pubDate>Tue, 10 Jan 2023 17:30:11 +0000</pubDate>
      <link>https://dev.to/ericeinerson/c-dictionary-2g9f</link>
      <guid>https://dev.to/ericeinerson/c-dictionary-2g9f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;As I have progressed in my quest to improve my skills in both programming and coding over the past year (I started with virtually no programming experience approximately 1 year ago in January 2022 at a coding bootcamp), I have tried to learn whatever I can about different facets of programming languages. Recently, I switched to C#, and this is my second summary of a topic related to this language. I hope it provides some useful information to some. Here is a short description of the C# dictionary.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a dictionary?
&lt;/h2&gt;

&lt;p&gt;A C# dictionary is a generic collection of key/value pairs. The syntax for a dictionary is as follows: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Dictionary&amp;lt;TKey,TValue&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;TKey refers to the key of the object; TValue refers to the value, which the key is mapped to. Between the two, only the value can be null if it is a reference type. The key must also be unique as duplicate keys will throw an exception.&lt;/p&gt;

&lt;p&gt;As stated above, this object is generic and defined within the System.Collections.Generic namespace. It is also dynamic, so it is able to grow, depending on the needs of the user, unlike a C# array, which is fixed in size. &lt;/p&gt;

&lt;p&gt;One difference between this object and the C# hashtable is that the hashtable is non-generic and is defined under the System.Collections namespace. See the references section for more on the C# hashtable. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why is a dictionary important?
&lt;/h2&gt;

&lt;p&gt;The dictionary is a useful way to minimize runtime complexity, as this object will usually run near O(1) constant time for retrieval (ContainsKey() method), insertion (Add() method), and deletion (Remove() method) of a value. &lt;/p&gt;

&lt;p&gt;When I say "near" (i.e. near O(1)) I mean that the complexity is not exactly, but is close enough to that value (O(1)) that it may safely be referred to that value (O(1)). On a graph showing input on the x-axis and runtime on the y-axis, a value near O(1) runtime would be much closer to the O(1) slope than it would be to the slopes of the next most common values (i.e. O(log n) or O(n)).&lt;/p&gt;

&lt;p&gt;Exceptions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the Count property of the dictionary exceeds the dictionary's capacity when using the Add() method, the capacity must be reset, causing the key/value pairs within the dictionary to be reallocated. This causes an O(n) runtime for Add() in this scenario.&lt;/li&gt;
&lt;li&gt;If you need to retrieve a specific value within the dictionary (ContainsValue() method), this performs a linear search and has an O(n) time complexity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8ynv9td4f9omd8341ye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8ynv9td4f9omd8341ye.png" alt="Big O Time Complexity Graph"&gt;&lt;/a&gt;&lt;br&gt;
Figure One: A graph displaying general trends of the Big O time complexities of the following: constant time (O(1)), logarithmic time (O(log n)), linear time (O(n)), and quadratic time (O(n^2)).&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use a dictionary
&lt;/h2&gt;

&lt;p&gt;Aside from above, here are a couple uses of a dictionary:&lt;/p&gt;

&lt;p&gt;When needing to utilize key/value mappings to store data, dictionaries allow for this advantage over arrays and lists, which use indices. &lt;/p&gt;

&lt;p&gt;If you would like to iterate over an object, use of the foreach() method to look at each key/value pair is possible with dictionaries as well as lists/arrays.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of dictionary use
&lt;/h2&gt;

&lt;p&gt;Below is an example of an implemented dictionary:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Dictionary&amp;lt;string,string&amp;gt; definitions = new Dictionary&amp;lt;string,string&amp;gt;();

definitions.Add("hue", "a color or shade");
definitions.Add("HTML", "hypertext markup language");
definitions.Add("chilly", "too cold to be comfortable");
definitions.Add("barrier", "an obstacle that prevents movement or access")


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The above code implements a dictionary that begins as an empty object. After each subsequent Dictionary.Add() method, a key with a word is added with a mapped value of its definition (i.e. "hue" mapping to "a color or shade").&lt;/p&gt;

&lt;h2&gt;
  
  
  Dictionary hierarchy
&lt;/h2&gt;

&lt;p&gt;The following are the interface implementations of the dictionary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;IReadOnlyDictionary&amp;lt;TKey,TValue&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;IDictionary&amp;lt;TKey,TValue&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;IReadOnlyCollection&amp;lt;KeyValuePair&amp;lt;TKey,TValue&amp;gt;&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;IDictionary&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Summary/Conclusions
&lt;/h2&gt;

&lt;p&gt;I hope this short review of C# dictionaries provided some value to you. I will be covering dictionaries more in depth in the future, but I wanted to start with this superficial summary. Thank you for reading.&lt;/p&gt;

&lt;p&gt;Below is a list of what I covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Dictionaries are generic collections used to store key/value pairs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dictionaries can be added to, removed from, counted, etc, with minimal runtime complexity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dictionaries have many advantages over lists/arrays, though each of these objects has its own optimal uses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dictionaries are similar to but not identical to hashtables in C#.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References and Further Reading
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-7.0" rel="noopener noreferrer"&gt;Dictionary Class: Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/c-sharp-dictionary-with-examples/" rel="noopener noreferrer"&gt;C# Dictionary With Examples: GeeksForGeeks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/c-sharp-hashtable-with-examples/" rel="noopener noreferrer"&gt;C# Hashtable With Examples: Geeksforgeeks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/7532678/what-is-the-complexity-of-these-dictionary-methods" rel="noopener noreferrer"&gt;What is the Complexity of These Dictionary Methods: Stack Overflow&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://levelup.gitconnected.com/big-o-time-complexity-what-it-is-and-why-it-matters-for-your-code-6c08dd97ad59" rel="noopener noreferrer"&gt;Big O Time Complexity Graph Reference(figure 1)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.add?redirectedfrom=MSDN&amp;amp;view=net-7.0#System_Collections_Generic_Dictionary_2_Add__0__1_" rel="noopener noreferrer"&gt;Dictionary Add Method With Examples: Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.count?view=net-7.0" rel="noopener noreferrer"&gt;Dictionary Count Method: Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.containskey?redirectedfrom=MSDN&amp;amp;view=net-7.0#System_Collections_Generic_Dictionary_2_ContainsKey__0_" rel="noopener noreferrer"&gt;Dictionary ContainsKey Method: Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.containsvalue?view=net-7.0" rel="noopener noreferrer"&gt;Dictionary ContainsValue Method: Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/c-sharp-dictionary-remove-method/" rel="noopener noreferrer"&gt;Dictionary Remove Method: GeeksForGeeks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.remove?view=net-7.0" rel="noopener noreferrer"&gt;Dictionary Remove Method: Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.keyvaluepair-2?view=net-7.0" rel="noopener noreferrer"&gt;KeyValuePair Struct: Microsoft&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/1838476/different-ways-of-adding-to-dictionary" rel="noopener noreferrer"&gt;Different Ways to Add to a Dictionary: Stack Overflow&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Overview of NuGet</title>
      <dc:creator>ericeinerson</dc:creator>
      <pubDate>Mon, 24 Oct 2022 00:47:12 +0000</pubDate>
      <link>https://dev.to/ericeinerson/overview-of-nuget-9l8</link>
      <guid>https://dev.to/ericeinerson/overview-of-nuget-9l8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;When I began learning about C# and the .NET framework, I ended up using some different external packages to bring in some extra functionality. For one specific project, I required use of the DocumentFormat.OpenXml package to create some word-processing elements. As I searched how to get the package (I was and still am a new software developer), I found out that I needed to use the NuGet Package Manager to install the OpenXml package. I realized that I did not know much about working with external libraries (i.e. through NuGet), so this post is about a superficial understanding of NuGet, including what it is, how to use it, why it is useful, when to use it, some examples of its use, and some additional helpful resources for further learning.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is NuGet?
&lt;/h2&gt;

&lt;p&gt;NuGet is a package manager for the .NET framework (ecosystem).&lt;/p&gt;

&lt;p&gt;NuGet is the "Microsoft-supported mechanism" for sharing .NET code. A NuGet package is a ZIP file with the .nupkg or .nupack extension that contains compiled code, related files, and information on the package. &lt;/p&gt;

&lt;p&gt;The packages are created by users who develop reusable code that they share with a host. Users of the third party code obtain it from the host and NuGet serves a an intermediate to transfer the code from host to user. &lt;/p&gt;

&lt;p&gt;A package is a "compiled library packed together with descriptive metadata into a sharable unit".&lt;/p&gt;

&lt;p&gt;The NuGet client app (nuget.exe) is also free and open source, so you have the ability to help improve this application.&lt;/p&gt;

&lt;h2&gt;
  
  
  When is NuGet useful?
&lt;/h2&gt;

&lt;p&gt;NuGet is useful for anyone wanting to bring additional functionality from custom libraries into a project, specifically for projects using the .NET framework. NuGet is supported by the following in its latest version (recommended latest is 6.3.0 at the time of this post): C#, Visual Basic, F#, WiX, and C++. &lt;/p&gt;

&lt;p&gt;NuGet is also useful for those who want to create their own custom functionality that other .NET users can utilize (see below for how to create and publish a NuGet package).&lt;/p&gt;

&lt;h2&gt;
  
  
  Why learn about NuGet
&lt;/h2&gt;

&lt;p&gt;Learning about external libraries and custom functionality will allow you to avoid the hassle of creating the functionality yourself, saving memory and time. People create NuGet packages to help others' code by making what they create reusable. This will also make you a more versatile programmer and coder since being familiar with external functionality shows that you understand and can apply others' code.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find and evaluate NuGet packages for your project
&lt;/h2&gt;

&lt;p&gt;Below, I have laid out an example of using a NuGet package for a project; however, see this link for a more detailed visualization and description of how to find and use NuGet packages for your projects:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/nuget/consume-packages/finding-and-choosing-packages" rel="noopener noreferrer"&gt;Microsoft docs: how to find and evaluate NuGet packages for your project&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of NuGet in use
&lt;/h2&gt;

&lt;p&gt;An example of a NuGet package I have used with a project is the DocumentFormat.OpenXml package. I used this to help format word-processing functionality and generate Microsoft Word documents in C#.&lt;/p&gt;

&lt;p&gt;Here are some steps to download the DocumentFormat.OpenXml NuGet package in Visual Studio:&lt;/p&gt;

&lt;p&gt;1) Either by using the Tools tab or right clicking on your solution, go to Manage NuGet packages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0rhwruqaeio9f02a8t5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0rhwruqaeio9f02a8t5l.png" alt="Go to Tools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhk4oul05bzmpe7tr5dhf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhk4oul05bzmpe7tr5dhf.png" alt="Select Manage NuGet Packages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2) Under the Browse tab, search for DocumentFormat.OpenXml, check it, and click "Add Package".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62pitt3orknli16uzwnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F62pitt3orknli16uzwnw.png" alt="Search for DocumentFormat.OpenXml"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3) Now you should be able to use the DocumentFormat.OpenXml NuGet package! Now all you have to do is type "using" at the top of your project to specify the namespace (in this case the namespace is the package). For this project, I used DocumentFormat.OpenXml.Wordprocessing to allow myself to create a Paragraph object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyeom7rxtuj98orsx93ru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyeom7rxtuj98orsx93ru.png" alt="Use the "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation and use of the NuGet CLI
&lt;/h2&gt;

&lt;p&gt;Since Visual Studio Code does not have an integrated NuGet package manager that can install packages, this section explains how you can get around that with the CLI, which is also useful to know without Visual Studio Code. This way, your use and acquisition of NuGet packages can be done in more ways than just the Visual Studio NuGet Package Manager&lt;/p&gt;

&lt;p&gt;Here are the steps to install and use the NuGet Command Line Interface, nuget.exe (Microsoft NuGet CLI Reference):&lt;/p&gt;

&lt;p&gt;Windows:&lt;br&gt;
1) Visit &lt;a href="https://nuget.org/downloads" rel="noopener noreferrer"&gt;https://nuget.org/downloads&lt;/a&gt; and select version 3.3 or higher to be compatible with Mono.&lt;/p&gt;

&lt;p&gt;2) Save the &lt;code&gt;nuget.exe&lt;/code&gt; file to a folder of your choice.&lt;/p&gt;

&lt;p&gt;3) Add the folder with the &lt;code&gt;nuget.exe&lt;/code&gt; file to your PATH environment variable&lt;/p&gt;

&lt;p&gt;macOS/Linux:&lt;br&gt;
1) Install Mono version 4.4.2 or higher&lt;/p&gt;

&lt;p&gt;2) Execute the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Download the latest stable `nuget.exe` to `/usr/local/bin`
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3) Create an alias, using the following script and add it to an appropriate file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create as alias for nuget
alias nuget="mono /usr/local/bin/nuget.exe"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4) Reload the shell and test the installation by entering the &lt;code&gt;nuget&lt;/code&gt; keyword&lt;/p&gt;

&lt;p&gt;See the reference link (NuGet CLI Reference) for more details on availability, commands, and applicability of the NuGet CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to create and publish a custom NuGet package
&lt;/h2&gt;

&lt;p&gt;Here is a short recap of a tutorial video on creating and publishing your own NuGet package via the .NET CLI in VS Code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a new class library via the CLI:&lt;br&gt;
&lt;br&gt;
&lt;code&gt;$ dotnet new classlib&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insert the code that you want to use for your library into the Class1.cs file (or whatever you renamed this file). The video writes simple functionality to log text to the console, and that's it. Your code is not required to be complex to be published.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Modify the package metadata in the AppLogger.csproj file (or whatever you renamed it). Here are some considerations and tips for this step:&lt;/p&gt;

&lt;p&gt;a. Create a uniquely-named PackageId element within the parent TargetFramework element (company.product.feature is a popular convention for this). Put the name between the PackageId element tags.&lt;/p&gt;

&lt;p&gt;b. Create an author element that specifies whomever is responsible for publishing this library (i.e. yourself, your company, etc.)&lt;/p&gt;

&lt;p&gt;c. Include a description element.&lt;/p&gt;

&lt;p&gt;d. Include a PackageLicenseExpression so others are able to use the library in their project(s) without restrictions.&lt;/p&gt;

&lt;p&gt;e. Create package tags to allow the user to search for your library with keywords.&lt;/p&gt;

&lt;p&gt;f. Include a repository URL if you have your source code saved in one.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Save the project and generate the NuGet package in the CLI using the following syntax:&lt;br&gt;
&lt;br&gt;
&lt;code&gt;$ dotnet pack&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Publish the NuGet package. One way to do this is by copying the path (ending in .nupkg) generated to the right of "Successfully created package" in the terminal, go to nuget.org, sign in, go to Upload, hit Browse, paste the path into the File name input, hit Open, verify your metadata in the found package, then hit Submit. Before it can be found on nuget.org, validation and indexing must be done, so the published library will take some time to be found on nuget.org.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use the link below to follow the descriptive video that came up with these steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/shows/nuget-101/create-and-publish-a-nuget-package-with-the-net-cli-5-of-5" rel="noopener noreferrer"&gt;Microsoft docs: how to create and publish a NuGet package with the .NET CLI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since your NuGet package has now been successfully uploaded to nuget.org, you can not see where to find what custom NuGet packages contain, their stability, and whether they would be useful for your project. The listing page should contain all of this information. Also, see the package's Info page to navigate to its website to acquire even more useful information.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;To drive home the main points from above:&lt;/p&gt;

&lt;p&gt;1) NuGet is the preferred .NET package manager for installing external functionality into projects.&lt;/p&gt;

&lt;p&gt;2) Any .NET language can use NuGet (C#, F#, Visual Basic, Wix, and C++ all support NuGet's latest version).&lt;/p&gt;

&lt;p&gt;3) You can install and use a NuGet package in Visual Studio by navigating to your Tools tab or right clicking your solution (shown above).&lt;/p&gt;

&lt;p&gt;4) Creating a NuGet package is relatively simple and can be done in a few steps (shown above).&lt;/p&gt;

&lt;p&gt;5) This post heavily referenced the Microsoft docs, so if you would like to learn more, I would highly recommend checking them out. A lot of the links referenced below will lead you to plenty of other documentation.&lt;/p&gt;

&lt;h2&gt;
  
  
  A few other bits of NuGet information/use
&lt;/h2&gt;

&lt;p&gt;1) NuGet can build create packages in Mono, and nuget.exe "builds and runs under Mono 3.2+" (Microsoft NuGet FAQ's)&lt;/p&gt;

&lt;p&gt;2) To check on the version of the NuGet Tools you have in Visual Studio, go to Help &amp;gt; About Microsoft Visual Studio and see the version next to NuGet Package Manager. Also, you can use the Package Manager Console (Tools &amp;gt; NuGet Package Manager &amp;gt; NuGet Package Manager Console) and enter &lt;code&gt;host&lt;/code&gt; to see th details of your version of NuGet.&lt;/p&gt;

&lt;p&gt;3) You can add your own commands to &lt;code&gt;nuget.exe&lt;/code&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  References and resources to learn more about NuGet
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/nuget/install-nuget-client-tools" rel="noopener noreferrer"&gt;install NuGet client tools&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/nuget/" rel="noopener noreferrer"&gt;NuGet documentation: Microsoft docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/nuget/resources/nuget-faq" rel="noopener noreferrer"&gt;NuGet FAQs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/nuget/what-is-nuget" rel="noopener noreferrer"&gt;What is NuGet and what does it do? Microsoft docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/shows/nuget-101/create-and-publish-a-nuget-package-with-the-net-cli-5-of-5" rel="noopener noreferrer"&gt;Microsoft docs: how to create and publish a NuGet package with the .NET CLI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/nuget/consume-packages/finding-and-choosing-packages" rel="noopener noreferrer"&gt;Microsoft docs: how to find and evaluate NuGet packages for your project&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/nuget/reference/nuget-exe-cli-reference" rel="noopener noreferrer"&gt;Microsoft docs: NuGet CLI Reference&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Transitioning from an Anatomy Student to a Software Engineer</title>
      <dc:creator>ericeinerson</dc:creator>
      <pubDate>Thu, 21 Apr 2022 19:22:17 +0000</pubDate>
      <link>https://dev.to/ericeinerson/transitioning-from-an-anatomy-student-to-a-software-engineer-2n1p</link>
      <guid>https://dev.to/ericeinerson/transitioning-from-an-anatomy-student-to-a-software-engineer-2n1p</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;This week I just finished my time as a student in Flatiron School's Software Engineering program. This was a path I had not considered until about fall of last year. I have always loved the idea of coding, and I have wanted to integrate it into my career for a really long time; however, I never thought that I would make software engineering my actual career. Here is some of my background on my journey to diving into the tech industry:&lt;/p&gt;

&lt;h2&gt;
  
  
  High School
&lt;/h2&gt;

&lt;p&gt;Back in high school, I had a major interest in math; I loved problem solving, and math came more easily to me than most other subjects. I took a couple of courses (Visual Basic and C++) in high school, and really enjoyed what I learned. At the time, I was just interested in being a biochemist or meteorologist, so coding seemed more like a fun hobby rather than a career.&lt;/p&gt;

&lt;h2&gt;
  
  
  College before Flatiron
&lt;/h2&gt;

&lt;p&gt;As an undergraduate who attended six universities, I had a fair amount of career path changes. I went from biochemistry, to athletic training, to pre-physical therapy, to exercise physiology (first bachelor's), to pre-med, to biochemistry (second bachelor's), to being an EMT, to anatomy with teaching certificate (master's), to anatomy education, finally to software engineering (bootcamp certificate). &lt;/p&gt;

&lt;p&gt;Software engineering was not part of my career outlook until thirteen years into my education, but I am glad I finally made it! Like I said, I have always thought it would be fantastic to include integrated coding in my career, but having gone through an intensive bootcamp, I feel excited to finally passionately work in an exponentially growing field.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Transition from PhD Student to a Bootcamp Student
&lt;/h2&gt;

&lt;p&gt;During my time as a PhD student, the final stage before transitioning into software engineering, I loved what I was learning; specifically, I loved teaching and anatomy. The only problem was that the working environment that I operated in did not mesh well with me. &lt;/p&gt;

&lt;p&gt;It was as though everything that I had been working towards suddenly seemed wrong. I decided based on how I felt to transition paths majorly into a path that I already had a little familiarity with, that would allow me to problem solve and apply math like I loved to do in high school, that would be flexible, and that would allow room for growth. This is what led me to choosing a bootcamp, specifically Flatiron School due to its great community and eagerness to get me into my new career path!&lt;/p&gt;

&lt;h2&gt;
  
  
  My Time in the Bootcamp
&lt;/h2&gt;

&lt;p&gt;Flatiron started out with an immense amount of pre-work that I had to complete before the program started. At first I was a little shocked at just how many hours I had to put into this work just to start orientation; now, after reflecting on my time in the bootcamp, I am thankful for the pre-work because not only did it prep me for the intense curriculum ahead, but I got that much more time to learn and take advantage of resources offered to me by the program.&lt;/p&gt;

&lt;p&gt;Shortly into the program, I was overwhelmed with the amount of content I was expected to absorb within a short period of time. On top of that, I was traveling, which made the absorption of material even more challenging; however, I was shocked by my first proud moment in the program, passing my first code challenge even though I absolutely thought I failed it. &lt;/p&gt;

&lt;p&gt;Into phase two, I developed more confidence in my coding abilities, but I was still pretty behind in lecture and keeping up with everything. I did feel like I was more prepared to take the second code challenge; however, I got stumped on one aspect of it, and I almost failed. This allowed me to self-reflect and try to change my learning style in order to prevent this from happening again.&lt;/p&gt;

&lt;p&gt;Into phase three, the content was overwhelming. I did my best to keep up, but there were several labs and readings that took me probably double the time to complete compared to either of the first two phases. It was great to get into the backend though, and I did develop more confidence in passing the next challenge. Unfortunately, I was not able to pass the third code challenge, but I passed the retake and kept trucking on. At this point, only one code challenge remained!&lt;/p&gt;

&lt;p&gt;Into phase four, I got to learn how to apply Ruby to Rails, and this made things a lot easier. Active Record and Ruby fundamentals in the previous phase were pretty overwhelming, and this phase had much fewer modules. Still, I fell into the trap of developing overconfidence and failed the last code challenge on the first try; however, I passed the retake without too much difficulty, and finally I was past all of the assessments! This was my greatest triumph because I only now needed to finish a couple projects in order to graduate!&lt;/p&gt;

&lt;p&gt;I feel like the fifth phase of Flatiron was actually the easiest. I was finally able to correctly apply my confidence, build out a project with features I had no clue about in the previous four phases, and take pride in the work I put into my new career. The best part: I never felt like the stress and exhaustion wore on me (unlike the PhD program); I love the busy work of coding, and I would never have thought that a program like Flatiron would give me a perspective that could compare something like my PhD program that I personally just did not mesh well with to an equally busy, yet rewarding entry point into my new career.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Authorization and Authentication in Ruby on Rails</title>
      <dc:creator>ericeinerson</dc:creator>
      <pubDate>Tue, 05 Apr 2022 21:59:49 +0000</pubDate>
      <link>https://dev.to/ericeinerson/authorization-and-authentication-in-ruby-on-rails-178k</link>
      <guid>https://dev.to/ericeinerson/authorization-and-authentication-in-ruby-on-rails-178k</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Authorization and authentication are two valuable areas of coding to understand. In this summary, I will be going over what authentication and authorization are and how to make a simple login form, including a username input that will be used to determine who the user is and whether they are authorized to view a post.&lt;/p&gt;

&lt;p&gt;By the way, when I use the word "auth" I am referring to both authorization and authentication as a whole, not one or the other and not something else entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Authentication versus authorization
&lt;/h2&gt;

&lt;p&gt;Authorization refers to what a user has access to; authentication refers to the verification of who a user is. Both of these are important for user security because validation of a user can prevent unwanted actions, such as admin access, from affecting the program/user in a negative way. &lt;/p&gt;

&lt;h2&gt;
  
  
  Cookies
&lt;/h2&gt;

&lt;p&gt;Cookies are data that are stored in a browser while a website is being used by a client. Cookies are generally client-side, not server-side. Their purpose is to remember information about the user, and they can be created as plain-text name-value pairs, such as user_name=eric.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cookies[:user_name] = "eric"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cookies can also be set as hashes and have attributes, such as expiration dates/times.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cookies[:login] = { :value =&amp;gt; "Eric", :expires =&amp;gt; Time.now + 1.hour}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This cookie, stored as the symbol :login, has a value set as "Eric" and it expires and is deleted 1 hour from the current time.&lt;/p&gt;

&lt;p&gt;One issue with cookies is that since they are generally plain-text, their information can be accessed by anyone, causing security concerns. Below is a special type of cookie, called a session, that helps resolve this security issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sessions
&lt;/h2&gt;

&lt;p&gt;Sessions are data that are stored on the server side. They are a specialized cookie that adds a signature to the cookie, encrypting it and preventing clients from tampering with its data. The following is a way to set up a session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;session[:user_id] = user.id
// stores the user's ID into an encrypted session 
ID that is several characters long
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, the session method will create a signature specifically for the  value of the [:user_id] key and assign the value of the user's ID to that signed value. This way, it is difficult for a malicious user to access the user_id.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code for allowing your program to use sessions and cookies
&lt;/h2&gt;

&lt;p&gt;Here is some starter code for allowing cookies and sessions to be used in your program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Application &amp;lt; Rails::Application
   config.middleware.use ActionDispatch::Cookies
   // allows one to use cookies in their program
   config.middleware.use ActionDispatch::Session:CookieStore
   // allows one to use sessions in their program
   config.action_dispatch.cookies_same_site_protection = 
   :strict
   // makes sure that cookies are only accepted 
   within applications on the same domain as the 
   program, rather than different domains, for 
   security of our program
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ApplicationController &amp;lt; ActionController::API
   include ActionController::Cookies
end
// This allows our application controller, 
which other controllers would generally 
inherit from, to use cookies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Creating a login form with a username
&lt;/h2&gt;

&lt;p&gt;Authentication could be done in Ruby with a create action using POST:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;post "/login" to sessions#create
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code, post refers to the POST restful action that allows one to persist a new instance of a login to the database; sessions refers to the controller that will be performing the create action via a create method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class SessionsController &amp;lt; ApplicationsController
   def create
      user = User.find_by(username:params[:username])
      session[:user_id] = user.id
      render json: user
   end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Below is how React could save the username in state. After making a POST request via a submit button on a React form, the default empty string of username (from useState("") is replaced with the username retrieved from the Ruby backend. The username is converted into a JavaScript object in the body of the request and then passed into the login callback function as a parameter called user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Login({ handleLogin }) {
  const [username, setUsername] = useState("");

  function handleSubmit(e) {
    e.preventDefault();
    fetch("/login", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ username }),
    })
      .then((r) =&amp;gt; r.json())
      .then((user) =&amp;gt; handleLogin(user));
  }

  return (
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;input
        type="text"
        value={username}
        onChange={(e) =&amp;gt; setUsername(e.target.value)}
      /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Login&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding authorization to the login
&lt;/h2&gt;

&lt;p&gt;The code above shows how one could take a user, save the user.id into the session[:user_id] and save the username in state, which shows on both the front end and back end that the user is authenticated. At the moment, all that is needed is the username, not the password.&lt;/p&gt;

&lt;p&gt;To take this a step further, an authorize method could be added that allows certain actions by the user to be restricted unless they have logged in with a username. Below is code that could be used to do this for a program that renders posts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class PostsController &amp;lt; ApplicationController
   before_action :authorize

   def show
      post = Post.find_by(id:params[:id])
      render json: post
   end

   private

   def authorize
      return render json: { error: "Unauthorized" }, status: 
      :unauthorized unless session.include? :user_id
   end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code prevents a user without a user_id stored in the session to access the post. Basically, before the show method is run, the authorize method runs (before_action ensures that :authorize will run before any method within the PostsController), returning an error unless a user_id is stored in the session as a truthy value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Here are some important takeaways from this blog:&lt;br&gt;
1) Authentication and authorization are not the same.&lt;br&gt;
2) POST is a useful RESTful action that can be applied to logging a user in.&lt;br&gt;
3) Cookies are usually client-side, plain text, and not secure; sessions are server-side, signed cookies that are more secure than other unsigned cookies.&lt;br&gt;
4) before_action allows one to use a method before any other methods within a class; the method, authorize, was the example used in this blog that determined whether or not a user could make a post.&lt;br&gt;
5) Certain middleware needs to be set up in order to use cookies in a Rails application; :strict is an example of how to prevent different domains from making requests for cookies.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password"&gt;https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/js/js_cookies.asp"&gt;https://www.w3schools.com/js/js_cookies.asp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.tutorialspoint.com/ruby-on-rails/rails-session-cookies.htm"&gt;https://www.tutorialspoint.com/ruby-on-rails/rails-session-cookies.htm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=IzbQAj_tcfI"&gt;https://www.youtube.com/watch?v=IzbQAj_tcfI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learning.flatironschool.com/"&gt;https://learning.flatironschool.com/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Event.stopPropagation() with regard to event bubbling.</title>
      <dc:creator>ericeinerson</dc:creator>
      <pubDate>Thu, 24 Mar 2022 23:00:36 +0000</pubDate>
      <link>https://dev.to/ericeinerson/eventstoppropagation-with-regard-to-event-bubbling-50gd</link>
      <guid>https://dev.to/ericeinerson/eventstoppropagation-with-regard-to-event-bubbling-50gd</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;An event in JavaScript is a way to affect an element, whether that is clicking, keying down, or loading DOM content causing some sort of change. Sometimes multiple elements that are closely related contain multiple event listeners, for example having multiple click events on a child/parent pair of elements. This could lead to issues because in JavaScript these events propagate to related elements, which could trigger events in either the parent and/or child. The following are some ways propagation could affect element events.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vAygUYcw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kqkubxlbcghu9eau2lm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vAygUYcw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kqkubxlbcghu9eau2lm.png" alt="event propagation image" width="880" height="663"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Event Capturing (phase one)
&lt;/h3&gt;

&lt;p&gt;This happens first in event propagation. When an event fires, the event propagates, starting with the highest parent, down each child until it reaches the target element.&lt;/p&gt;

&lt;h3&gt;
  
  
  Targeting
&lt;/h3&gt;

&lt;p&gt;This occurs when the event reaches its target.&lt;/p&gt;

&lt;h3&gt;
  
  
  Event Bubbling (phase two)
&lt;/h3&gt;

&lt;p&gt;Bubbling happens after the targeting phase occurs. Event bubbling refers to a propagation of events from the target element (innermost element) all the way up to the highest parent (outermost element). This is usually the phase that causes events to fire in JavaScript as it is generally the default event setting. Therefore, the event capturing and targeting phases do not generally cause propagation issues in JavaScript unless the settings are different than default.&lt;/p&gt;

&lt;p&gt;For example, if a button were created within a form and both had an attached click event listener, the button would fire first when clicked, then the form. stopPropagation within the button would prevent the form from firing after the button is clicked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Event.stopPropagation
&lt;/h2&gt;

&lt;p&gt;Event.stopPropagation is a method that allows one to stop the propagation of events. This would affect any event capturing and and event bubbling. &lt;/p&gt;

&lt;h2&gt;
  
  
  Event.preventDefault
&lt;/h2&gt;

&lt;p&gt;This method prevents the default action of the element from firing upon completion of the event. This usually causes the page to refresh, as this is usually the default for JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of where stop propagation would be useful
&lt;/h2&gt;

&lt;p&gt;Below I have some screenshots of some nested elements, which give a visual for Event.stopProgagation:&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpage without any events
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z1CuDy0L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j0qmq6dzyyktoiyx9ym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z1CuDy0L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j0qmq6dzyyktoiyx9ym.png" alt="webpage without events" width="816" height="816"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This represents a few divs, a form, and a button (labeled 1-5). 1 is a parent of 2, 2 is a parent of 3, etc. Below is the code using stopPropagation and preventDefault:&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML/CSS Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9yQVa2SQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3zv40xs9j431j0kbj25i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9yQVa2SQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3zv40xs9j431j0kbj25i.png" alt="HTML" width="862" height="784"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the elements are all nested within each other. This means that they could all propagate events onto one another, whether that is from 1-5 via event capturing or 5-1 via event bubbling. Since JavaScript defaults to event bubbling, the events would all fire from 5-1 without stopPropagation.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Code
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8gIfG840--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8utwoffwqe5keh1nhx67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8gIfG840--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8utwoffwqe5keh1nhx67.png" alt="JavaScript" width="880" height="527"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Alerts during each event firing show that they happen separately:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DLPw_TzT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oa6ulmfz23xx9cpf272b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DLPw_TzT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oa6ulmfz23xx9cpf272b.png" alt="Alert" width="880" height="882"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This shows that after each event firing is individual and separate. After each event, an alert pops up with the associated element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Event.stopPropagation stops the event firing after the second event
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T-qgtX9R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5emd7d7lyiecam15i60.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T-qgtX9R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5emd7d7lyiecam15i60.png" alt="inner black" width="818" height="826"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Due to the conditional statement within JavaScript, the stopPropagation method fires when the for loop hits i=3, therefore preventing further propagation after the second event is triggered.&lt;/p&gt;

&lt;h2&gt;
  
  
  Above second loop (i===3), stopPropagation does not stop the event from propagating all the way to the outermost element.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h0ZN3Szp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2q3wr5bu8fw3fl15uhl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h0ZN3Szp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2q3wr5bu8fw3fl15uhl.png" alt="Outer black" width="818" height="816"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Event.preventDefault
&lt;/h2&gt;

&lt;p&gt;Since preventDefault is written within the loop, this will prevent the boxes from changing from black to their default color. If preventDefault were removed, the boxes would not remain black after clicking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Event.stopImmediatePropagation
&lt;/h2&gt;

&lt;p&gt;This method is similar to Event.stopPropagation; however, instead of only stopping the event propagation chain (whether that is within the out-to-in event capturing or the in-to-out bubbling), this method additionally stops all events from firing within the same element. This is different from Event.stopPropagation because Event.stopPropagation will allow other event handlers within the same event to fire, just not the propagation of events to a subsequent element.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Here are the main takeaway points:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Events propagate between elements both outside-to-inside (capturing) and inside-to-outside (bubbling).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are a few methods that are related to event firing, and each has their own function:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;stopPropagation: prevents further propagating between &lt;br&gt;
elements&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;preventDefault: prevents the default action of the &lt;br&gt;
element from happening once the event fires (i.e. &lt;br&gt;
refreshing the screen).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;stopImmediatePropagation: prevents the other event &lt;br&gt;
handlers on the same element from firing, in addition to &lt;br&gt;
stopping event propagation between elements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Events happen independently of each other in a certain order (via capturing and bubbling), not all at once.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=wqWQvCsLyfg"&gt;stopPropagation vs preventDefault tutorial by EDUDREAMS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=UWCvbwo9IRk"&gt;stopPropagation vs preventDefault tutorial by dcode&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.pixiz.com/frame/Spongebob-Bubble-3180141"&gt;Spongebob photo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ehsankorhani.com/"&gt;Event propagation image&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/a-simplified-explanation-of-event-propagation-in-javascript-f9de7961a06e/"&gt;Simplified explanation of stopPropagation in JavaScript&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/event-propagation-event-bubbling-event-catching-beginners-guide/"&gt;Event bubbling and catching beginner's guide&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.educative.io/edpresso/what-is-event-capturing-in-javascript"&gt;What is event capturing?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Event/stopPropagation"&gt;Event.stopPropagation MDN&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Looking At Big O Notation With A Few Examples</title>
      <dc:creator>ericeinerson</dc:creator>
      <pubDate>Tue, 15 Mar 2022 23:32:23 +0000</pubDate>
      <link>https://dev.to/ericeinerson/looking-at-big-o-notation-with-an-algorithm-2kp4</link>
      <guid>https://dev.to/ericeinerson/looking-at-big-o-notation-with-an-algorithm-2kp4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction (what is Big O)
&lt;/h2&gt;

&lt;p&gt;Big O notation is a way to describe the time complexity of a function. The larger an input is, the longer it will take for the function to run, and this runtime is expressed by Big O. This is different from directly measuring the exact time it takes each function to run; instead of measuring in terms of seconds, Big O gives us an approximation based on the function's input (n).&lt;/p&gt;

&lt;h2&gt;
  
  
  Main points
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;O(n) is abstract.&lt;/li&gt;
&lt;li&gt;Directly measuring run time is concrete.&lt;/li&gt;
&lt;li&gt;The larger the input n is, the larger Big O becomes.&lt;/li&gt;
&lt;li&gt;time complexity = how the run time of a function increases as the input increases&lt;/li&gt;
&lt;li&gt;Big O often looks at the "worst case" scenario (i.e. the most iterations possible).&lt;/li&gt;
&lt;li&gt;Big O and O(n) are synonymous for the purposes of this post.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What can O(n) look like?
&lt;/h2&gt;

&lt;p&gt;I will be going through the following examples of O(n):&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;O(n)&lt;/li&gt;
&lt;li&gt;O(1)&lt;/li&gt;
&lt;li&gt;O(n^2)&lt;/li&gt;
&lt;li&gt;O(log(n))&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Example of O(n) using array iteration
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exampleArry = [1, 3, 6, 9, 24]

function findNumber() {
exampleArry.find(element =&amp;gt; element &amp;gt; 8)
}

findNumber()
// 9
// This will create an O(n) of n = 4 iterations 
// since find() begins at the left and ends 
// at the right

anotherArry = [1, 5, 7, 9, 20, 130, 260, 340, 400]

function findNumber() {
anotherArry.find(element =&amp;gt; element &amp;gt; 350)
}

findNumber()
// 400
// This function uses an O(n) of n = 9 
// iterations, which means the function will 
// theoretically take longer to run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These examples describe Big O by using the function findNumber() to iterate through each element in the exampleArry. The number of iterations is a way to assign a value to n. Therefore, if find() needed to make 3 iterations to find a number (i.e. finding an index of 2), n would equal 3, making O(n) = 3.&lt;/p&gt;

&lt;p&gt;If you need a refresher on the find() method, check out a blog I posted comparing different JavaScript iteration methods:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/ericeinerson/comparing-methods-of-array-iteration-in-javascript-1h03"&gt;https://dev.to/ericeinerson/comparing-methods-of-array-iteration-in-javascript-1h03&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Visual of an O(n) based on exampleArry and anotherArry
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mQzLtsPC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovoghi9t36dfjh3lpe5t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mQzLtsPC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ovoghi9t36dfjh3lpe5t.png" alt="Linear slope graph" width="880" height="636"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This image shows a linear time complexity, which means n is increasing in a linear manner compared to the input. In this example, n = 1, which means O(n) and the input increase at a 1:1 ratio. If the ratio were 2:1 or 1:2, this would still be a linear relationship. These would also still be generalized as O(n), not O(2n) or O(n/2). &lt;/p&gt;

&lt;h2&gt;
  
  
  Why is Big O important
&lt;/h2&gt;

&lt;p&gt;Big O is a useful tool because figuring out how long a function will take to run may not be that easy. Different languages, running other programs at the same time, one's computer's processing speed, and other factors could make this difficult. Big O is convenient for producing a theoretical model for how long the function should take to run, based on how one's function is written. &lt;/p&gt;

&lt;h2&gt;
  
  
  Here is how quickly Big O would grow, based on some examples:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  O(1)
&lt;/h2&gt;

&lt;p&gt;Sometimes, a function will run at the same speed no matter what the size of the input is. This is called a constant time complexity with regards to Big O. No matter how large the input is, Big O is still going to remain the same value with O(1).&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of O(1)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exampleArry = [1, 3, 6, 9, 24]

function printNumber(i) {
return exampleArry[i]
}

findNumber(2)
// 6
// This function identifies a single index in exampleArry and returns it. The time needed in order to return the index is just a single step, no matter which index is chosen, hence O(1).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Graph showing O(1) line
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VtXf7mPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/56jy1pi2rmfcnv8uuh67.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VtXf7mPx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/56jy1pi2rmfcnv8uuh67.png" alt="Constant slope graph" width="806" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  O(n^2)
&lt;/h2&gt;

&lt;p&gt;Big O(n^2) describes a time complexity whose run time increases quadratically compared to its input. Therefore, large inputs are going to have extremely large Big O's. This input/time relationship is likely the most important for those working with large inputs because a sizable input could create a slow-running function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of O(n^2)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exampleArry = [1, 4, 5, 1, 6, 4]
function findMatch() {
    for (let i = 0; i &amp;lt; exampleArry.length; i++) {
        for (let j = 0; j &amp;lt; exampleArry.length; j++) {
            if ((exampleArry[i] === exampleArry[j]) &amp;amp;&amp;amp; (i !== j) {
                return exampleArry[i]
            }
        }
    }
}

findMatch()
// 1
// This function's worst case involves 36 iterations
// because exampleArry contains 6 indices (6 iterations
// for i each with 6 iterations for j =&amp;gt; 36 possible iterations)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Graph showing O(n^2) curve
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L_JML5ez--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajkcuq463bp66pereq7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L_JML5ez--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ajkcuq463bp66pereq7t.png" alt="Quadratic curve graph" width="880" height="749"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  O(log(n))
&lt;/h2&gt;

&lt;p&gt;This describes a logarithmic increase in time compared to the input and acts in the opposite way as O(n^2). The larger the input for O(log(n)), the less time is added per iteration. Big O(log(n)) would be ideal for larger inputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example of O(log(n))
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findLog(n) {
    count = 0;
    for (let i = 1; i &amp;lt; n; i = i * 2) {

        count++;
    }
    return count
}

findLog(5)
// 2
findLog(10000)
// 13
// This function finds the log of n (not taking into account // decimals). The solution is going to be how many times i
// can be doubled (hence log base 2) until it reaches a value // greater than n.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Graph showing Log (base 2) of n
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r_xgNAjc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xpqxe9raxun4ibmcppf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r_xgNAjc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7xpqxe9raxun4ibmcppf.png" alt="Logarithmic curve" width="602" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://medium.com/karuna-sehgal/a-simplified-explanation-of-the-big-o-notation-82523585e835"&gt;https://medium.com/karuna-sehgal/a-simplified-explanation-of-the-big-o-notation-82523585e835&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Big_O_notation"&gt;https://en.wikipedia.org/wiki/Big_O_notation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Algorithm"&gt;https://developer.mozilla.org/en-US/docs/Glossary/Algorithm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.in/data-structures-tutorial/big-o-notation-and-algorithm-analysis/"&gt;https://www.w3schools.in/data-structures-tutorial/big-o-notation-and-algorithm-analysis/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=D6xkbGLQesk"&gt;https://www.youtube.com/watch?v=D6xkbGLQesk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://web.mit.edu/16.070/www/lecture/big_o.pdf"&gt;https://web.mit.edu/16.070/www/lecture/big_o.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learning.flatironschool.com/courses/4985/pages/big-o-notation?module_item_id=352002"&gt;https://learning.flatironschool.com/courses/4985/pages/big-o-notation?module_item_id=352002&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://learning.flatironschool.com/courses/4985/pages/big-o-examples?module_item_id=352003"&gt;https://learning.flatironschool.com/courses/4985/pages/big-o-examples?module_item_id=352003&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://socratic.org/questions/how-do-you-complete-a-table-for-the-rule-y-3x-2-then-plot-and-connect-the-points"&gt;https://socratic.org/questions/how-do-you-complete-a-table-for-the-rule-y-3x-2-then-plot-and-connect-the-points&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freemathhelp.com/slope-line/"&gt;https://www.freemathhelp.com/slope-line/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/17122807/big-o-ologn-code-example"&gt;https://stackoverflow.com/questions/17122807/big-o-ologn-code-example&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Binary_logarithm"&gt;https://en.wikipedia.org/wiki/Binary_logarithm&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Comparing Methods of Array Iteration in JavaScript</title>
      <dc:creator>ericeinerson</dc:creator>
      <pubDate>Thu, 17 Feb 2022 21:53:19 +0000</pubDate>
      <link>https://dev.to/ericeinerson/comparing-methods-of-array-iteration-in-javascript-1h03</link>
      <guid>https://dev.to/ericeinerson/comparing-methods-of-array-iteration-in-javascript-1h03</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;An array is an object that behaves like a list. Arrays are useful because they are an organized sequence of elements that can be used together to perform powerful tasks with a collection of data. &lt;/p&gt;

&lt;p&gt;Array iteration is a skill that uses many methods, some similar and others much different. It involves sifting through the array's indices and either acting on one or more elements/indices or outputting something based on what is already within the array. &lt;/p&gt;

&lt;p&gt;The following are four methods of array iteration that I think would be useful to compare and contrast:&lt;/p&gt;

&lt;h2&gt;
  
  
  map()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;takes in a callback function as an argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;returns a new array with each element being the return value of the callback function &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Here is a simple algebraic example of how to use map()
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const exampleArry = [1, 3, 6]

const newArry = exampleArry.map( (number) =&amp;gt; number * 3)

console.log(newArry)
// [3, 9, 18]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each element in exampleArry was passed into the callback function that map took as a parameter, which was called "number". That callback function returned each "number" multiplied by 3, then returned an array with each result of the callback function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here is a way to use map on a string
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const exampleArry = ["orange", "apple", "strawberry"]

const notTheSameArry = exampleArry.map( (fruit) =&amp;gt; fruit + " juice")

const anotherArry = exampleArry.map( (fruit) =&amp;gt; "organic " + fruit)

console.log(exampleArry)
// ["orange", "apple", "strawberry"]

console.log(notTheSameArry)
// ["orange juice", "apple juice", "strawberry juice"]

console.log(anotherArry)
// ["organic orange", "organic apple", "organic strawberry"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  find()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;takes in a callback function as an argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;returns the first element of the array that satisfies the callback function&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Here is a way to use find()
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const exampleArry = [1, 3, 5, 7]

const notTheSameArry = exampleArry.find( (number) =&amp;gt; number &amp;gt; 6)

const anotherArry = exampleArry.find( (number) =&amp;gt; number &amp;gt; 4)

console.log(exampleArry)
// [1, 3, 5, 7]

console.log(notTheSameArry)
// 7

console.log(anotherArry)
// 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  filter()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;takes in a callback function as an argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;returns a new array with each element of the original array that satisfies the callback function&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Here is a way to use filter()
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const exampleArry = [1, 3, 5, 7]

const notTheSameArry = exampleArry.find( (number) =&amp;gt; number &amp;gt; 3)

const anotherArry = exampleArry.find( (number) =&amp;gt; number &amp;gt; 1)

console.log(exampleArry)
// [1, 3, 5, 7]

console.log(notTheSameArry)
// [5, 7]

console.log(anotherArry)
// [3, 5, 7]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  forEach()
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;takes in a callback function as an argument&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;returns undefined&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;logs the result of each affected element in the original array&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Here is a way to use forEach()
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const exampleArry = [1, 3, 5, 7]

const notTheSameArry = exampleArry.find( (number) =&amp;gt; number * 4)

const anotherArry = exampleArry.find( (number) =&amp;gt; number * 2)

console.log(exampleArry)
// [1, 3, 5, 7]
// return value would be [1, 3, 5, 7]

console.log(notTheSameArry)
// [4, 12, 20, 28]
// return value would be undefined

console.log(anotherArry)
// [2, 6, 10, 14]
// return value would be undefined

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Comparing and contrasting these four iteration methods
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;map(), filter(), and find() all return a value; forEach() returns undefined.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;map() and filter() both return a new array; find() returns an element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;map() and forEach() both act on every iterable element in an array; filter() and find() check on iterable element(s) in an array rather than acting on each element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;map(), filter(), and find() can normally easily be used on top of one another on the same variable; forEach() is not as easy to use on top of map(), filter(), and find().&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All of these methods use a callback function as an argument.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example of how you could or could not use these iteration methods together:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const exampleArry = [1, 3, 5, 7]

const notTheSameArry = exampleArry.map( (number) =&amp;gt; number + 1).filter( (number) =&amp;gt; number &amp;gt; 2).find( (number) =&amp;gt; number &amp;gt; 4)

const anotherArry = exampleArry.forEach( (number) =&amp;gt; number + 1).filter( (number) =&amp;gt; number &amp;gt; 2).find( (number) =&amp;gt; number &amp;gt; 4)

console.log(exampleArry)
// [1, 3, 5, 7]

console.log(notTheSameArry)
// This will return 6

console.log(anotherArry)
// This will return an error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation (notTheSameArry)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This variable first mapped over the exampleArry array, adding 1 to each element in this array. This map() method returned a new array of [2, 4, 6, 8] before being going through filter(). &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The next method, filter(), iterated through the newly mapped array and returned another array based on each element being greater than 2. This lead to a new returned array of [4, 6, 8] before find() was implemented. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The final method used, find(), iterated through the newly filtered array and returned the element that first satisfied its callback function. Since the callback function called for a an argument that was greater than 4, the element 6 was returned. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Explanation (anotherArry)
&lt;/h2&gt;

&lt;p&gt;This variable assignment would return an error. It acts almost the same as the const notTheSameArry, except for one detail: forEach() returns an undefined. Therefore, the next method used, filter(), would throw an error due to the undefined not being iterable. Furthermore, find() would not even be able to attempt to iterate because the syntax of this variable assignment broke when filter() tried to iterate over the undefined return value of anotherArry.&lt;/p&gt;

&lt;h2&gt;
  
  
  The following are other iteration methods with one-sentence descriptions that you could check out if you are interested:
&lt;/h2&gt;

&lt;h2&gt;
  
  
  entries()
&lt;/h2&gt;

&lt;p&gt;This method returns an object with the keys and key values of an array.&lt;/p&gt;

&lt;h2&gt;
  
  
  every()
&lt;/h2&gt;

&lt;p&gt;This method returns a boolean based on every element in the array satisfying a testing function.&lt;/p&gt;

&lt;h2&gt;
  
  
  findIndex()
&lt;/h2&gt;

&lt;p&gt;This method returns the index of the first element that satisfies the testing function&lt;/p&gt;

&lt;h2&gt;
  
  
  for...in
&lt;/h2&gt;

&lt;p&gt;This method iterates over enumerable properties of an object &lt;/p&gt;

&lt;h2&gt;
  
  
  for...of
&lt;/h2&gt;

&lt;p&gt;This method iterates over iterable properties of an object&lt;/p&gt;

&lt;h2&gt;
  
  
  from()
&lt;/h2&gt;

&lt;p&gt;This method creates a new array by iterating through an object and assigning each iterable element an index &lt;/p&gt;

&lt;h2&gt;
  
  
  includes()
&lt;/h2&gt;

&lt;p&gt;This method returns a boolean value depending on whether or not the method's argument is within the array.&lt;/p&gt;

&lt;h2&gt;
  
  
  indexOf()
&lt;/h2&gt;

&lt;p&gt;This method finds an array element and returns its index.&lt;/p&gt;

&lt;h2&gt;
  
  
  keys()
&lt;/h2&gt;

&lt;p&gt;This method returns the keys of an array in a new object.&lt;/p&gt;

&lt;h2&gt;
  
  
  lastIndexOf()
&lt;/h2&gt;

&lt;p&gt;This method is the same is indexOf(), but it returns the last occurrence of the element in its array. &lt;/p&gt;

&lt;h2&gt;
  
  
  reduce()
&lt;/h2&gt;

&lt;p&gt;This method calls a function on each element in an array, which will return a value that consolidates the values of each index into one element. &lt;/p&gt;

&lt;h2&gt;
  
  
  reduceRight()
&lt;/h2&gt;

&lt;p&gt;This method is the same as reduce(), but it iterates through the array from right to left instead of left to right.&lt;/p&gt;

&lt;h2&gt;
  
  
  some()
&lt;/h2&gt;

&lt;p&gt;This method returns a boolean based on whether some of the elements of an array satisfy a testing function.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Here are some resources I used to familiarize myself with arrays and array iteration, which helped me construct this post:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/how-to-use-array-methods-in-javascript-iteration-methods"&gt;https://www.digitalocean.com/community/tutorials/how-to-use-array-methods-in-javascript-iteration-methods&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://levelup.gitconnected.com/the-array-iterators-cheatsheet-javascript-9d0cfa03f4"&gt;https://levelup.gitconnected.com/the-array-iterators-cheatsheet-javascript-9d0cfa03f4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/js/js_array_iteration.asp"&gt;https://www.w3schools.com/js/js_array_iteration.asp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.tabnine.com/academy/javascript/how-to-use-the-forof-statement-in-javascript/"&gt;https://www.tabnine.com/academy/javascript/how-to-use-the-forof-statement-in-javascript/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/js-array-find-method"&gt;https://www.digitalocean.com/community/tutorials/js-array-find-method&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/4-main-differences-between-foreach-and-map/"&gt;https://www.freecodecamp.org/news/4-main-differences-between-foreach-and-map/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.google.com/url?sa=i&amp;amp;url=https%3A%2F%2Fwww.kirupa.com%2Fjavascript%2Flooping_through_array.htm&amp;amp;psig=AOvVaw0IcpiQhcHANUUAl2P_uFsa&amp;amp;ust=1645220133858000&amp;amp;source=images&amp;amp;cd=vfe&amp;amp;ved=0CAsQjRxqFwoTCNjuzOPYh_YCFQAAAAAdAAAAABAD"&gt;https://www.google.com/url?sa=i&amp;amp;url=https%3A%2F%2Fwww.kirupa.com%2Fjavascript%2Flooping_through_array.htm&amp;amp;psig=AOvVaw0IcpiQhcHANUUAl2P_uFsa&amp;amp;ust=1645220133858000&amp;amp;source=images&amp;amp;cd=vfe&amp;amp;ved=0CAsQjRxqFwoTCNjuzOPYh_YCFQAAAAAdAAAAABAD&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://javascript.plainenglish.io/understanding-and-applying-array-methods-in-javascript-df7873ad611"&gt;https://javascript.plainenglish.io/understanding-and-applying-array-methods-in-javascript-df7873ad611&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
