<?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: lfriedrichs</title>
    <description>The latest articles on DEV Community by lfriedrichs (@lfriedrichs).</description>
    <link>https://dev.to/lfriedrichs</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%2F341259%2F51c4807e-e8fc-4720-962a-b258c8eccaf8.png</url>
      <title>DEV Community: lfriedrichs</title>
      <link>https://dev.to/lfriedrichs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lfriedrichs"/>
    <language>en</language>
    <item>
      <title>Why you should use === and not == in JS</title>
      <dc:creator>lfriedrichs</dc:creator>
      <pubDate>Thu, 09 Apr 2020 21:53:40 +0000</pubDate>
      <link>https://dev.to/lfriedrichs/why-you-should-use-and-not-in-js-23ef</link>
      <guid>https://dev.to/lfriedrichs/why-you-should-use-and-not-in-js-23ef</guid>
      <description>&lt;p&gt;I'm currently in Flatiron School's Immersive Software Engineering Bootcamp. We began with RUBY where == is totally fine to use in equality statements. We have no switched to JavaScript and with it comes an important difference. In JavaScript the default equality comparison is ===, where as a special equality case (==) can be used where appropriate. &lt;/p&gt;

&lt;p&gt;Here is a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness"&gt;link&lt;/a&gt; to mozilla's explanation on the subject. To highlight their content, here's a summary.&lt;/p&gt;

&lt;p&gt;=== is a strict equality comparison while == is an abstract equality comparison. Because == is abstract, you should only use it in special cases WHERE YOU WANT THE DESIRED BEHAVIOR. 3 === '3' will return FALSE as expected but 3 == '3' will return TRUE. For simple comparison this is fine, but as you get deep into your application you may unintentionally create an error when you receive unexpected input, or if you are using a conditional to control your input it might not filter out a case for which you did not account. So in short, it's good practice to stick with the === unless you have a specific reason to use ==.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Shift and Push vs Splice in Javascript</title>
      <dc:creator>lfriedrichs</dc:creator>
      <pubDate>Wed, 11 Mar 2020 00:02:12 +0000</pubDate>
      <link>https://dev.to/lfriedrichs/shift-and-push-vs-splice-in-javascript-158</link>
      <guid>https://dev.to/lfriedrichs/shift-and-push-vs-splice-in-javascript-158</guid>
      <description>&lt;p&gt;A classmate of mine had a whiteboard challenge as follows: make a function that accepts an array and a number, N. Rotate the values in that array to the left N times. Two solutions were suggested. Use array.push() and array.shift() or use array.slice(). Below are the two code snippets:&lt;/p&gt;

&lt;p&gt;function arrayRotationUnshiftPush(array, numberOfRotations) {&lt;br&gt;
    for (let i = 0; i &amp;lt; numberOfRotations%array.length; i++) {&lt;br&gt;
        array.push(array.shift());&lt;br&gt;
    }&lt;br&gt;
    return array&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function arrayRotationSplice(array, numberOfRotations) {&lt;br&gt;
    index = numberOfRotations%array.length;&lt;br&gt;
    return [...array.splice(index), ...array]&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;To test out which approach is faster, I created a dummy array if integers:&lt;/p&gt;

&lt;p&gt;let array = []&lt;/p&gt;

&lt;p&gt;for (i = 0; i&amp;lt;20000; i++) {&lt;br&gt;
    array[i] = i;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Then I called the functions on the array and used Date.now() to record the time before and after:&lt;/p&gt;

&lt;p&gt;let time = Date.now();&lt;br&gt;
for (i = 0; i&amp;lt;20; i++) {&lt;br&gt;
arrayRotationUnshiftPush(array, 1500);&lt;br&gt;
}&lt;br&gt;
console.log(Date.now() - time);&lt;/p&gt;

&lt;p&gt;The results were surprising. When the array length became very long, splice was significantly faster. When the number of times each function was called became very long, splice was again much faster. Finally, the deeper into the array, the faster splice became compared to shift and push. All of this suggest that invoking a method adds additional runtime on a very small level that when scaled up creates a noticeable difference in run time.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Using Active Record and Rails - Relationships</title>
      <dc:creator>lfriedrichs</dc:creator>
      <pubDate>Mon, 02 Mar 2020 23:19:59 +0000</pubDate>
      <link>https://dev.to/lfriedrichs/using-active-record-and-rails-relationships-3624</link>
      <guid>https://dev.to/lfriedrichs/using-active-record-and-rails-relationships-3624</guid>
      <description>&lt;p&gt;Active Record and Rails is meant to make your life easier, but it can also create annoying bugs if you don't understand the reasoning behind the syntax. I'll talk about a bug I ran into recently and explain the nature of relationships in Active Record and what is being interpreted by Rails. &lt;/p&gt;

&lt;p&gt;First, the bug. So I was in the middle of coding a simple web app for heroine(s) and their power(s). I set up a many to many relationship for powers and heroines through a join table (heroine_powers). PRO TIP: you should be using underscores in your SQL and file names, however for classes you should be using CamelCase (models and controllers). I attempted to set the add a power to my heroine by using collection_select (in my heroine create view) on a list of power ids, passing it to heroine_parameters (in my controller). My parameters was set to collect power_ids: []. However, the power was not set when I displayed the heroine. What happened? &lt;/p&gt;

&lt;p&gt;Let's dive into relationships in Active Record to explain where I went wrong. The Heroine class has many Power(s) through HeroinePower(s) and therefore should call powers belonging to a heroine as heroine.powers. Check. Similarly the Power class has many Heroine(s) through HeroinePower(s) and would call them as power.heroines. This means that the heroine class stores its powers as a list of power_id(s) in an array E.g. heroine.powers =&amp;gt; [1,4,8]. Check? Sort of ...&lt;/p&gt;

&lt;p&gt;Next we can look at collection_select. This function displays a dropdown menu of things to choose in the format: :key, Source, :store_this_key, :display_this_key. That means for my code :power_ids, Power.all, :id, :name, params will contain a key :power_ids with the :id of the selected power. If I put :power_ids[] this would cause an error as collection.select only returns ONE value. It is not looking for an array to place an number in, it is looking to set a value for a key-value pair. &lt;/p&gt;

&lt;p&gt;So, active record has an array of powers but collection.select returns one number. Uh oh. Can this still work? YES. Looking again at heroine_parameters, we can update the key to :power_ids. Even though this is a plural word, the value only contains one number. Why does it need to be plural even though it only stores one number? Because Active Record is looking for a plural value because each heroine HAS MANY powerS (emphasis on the S -- don't really capitalize it). So Active Record can handle receiving a single number for the value of power_ids and create the relationship through the join table. AMAZING. &lt;/p&gt;

&lt;p&gt;But what about the original code power_ids: []? What would this be used for? Well if you are using collection_check_boxes it has the format :power_ids[], Power.all, :id, :name. Why will this work? Because collection_check_boxes wants to give you the ability to select multiple entries. So it needs to pass back this list of power_ids in an array. This means the heroine_parameters would need to have power_ids: [] instead of :power_ids. Is this a problem? No not really. &lt;/p&gt;

&lt;p&gt;As a developer you should never have different collection options for the same attribute of the object. It just doesn't make sense. But if for some reason you REALLY needed this feature, you could use a second collection option through the Power create/edit view and utilize the ability of both Power and Heroine being able to set relationships through the heroine_power join table.&lt;/p&gt;

&lt;p&gt;So to recap, many-to-many means AR needs to see that S on the end of things. Collection methods and parameter input syntax need to match. Single to single and plural to plural in your view/controller is independent of AR (though you can't use plural-to-plural with a has_one relationship).&lt;/p&gt;

</description>
      <category>rails</category>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>First Post!!!</title>
      <dc:creator>lfriedrichs</dc:creator>
      <pubDate>Tue, 25 Feb 2020 00:34:08 +0000</pubDate>
      <link>https://dev.to/lfriedrichs/first-post-28m9</link>
      <guid>https://dev.to/lfriedrichs/first-post-28m9</guid>
      <description>&lt;p&gt;I've started the software engineering immersive bootcamp at Flatiron School! This is week 5 for me. I've progressed through Ruby and some of it's libraries (ActiveRecord, etc.) and am currently deep diving into Rails :)&lt;/p&gt;

&lt;p&gt;But enough about code, I've been asked to explain WHY I WANT TO CODE. And so here we go. I majored in civil engineering in college and pursued a master's degree only to realize that I REALLY disliked the industry. Like building things is cool, but turns out different professions have can VERY different work cultures and expectations. So in short, I realized I was a fish out of water at my former job and decided to try something else.&lt;/p&gt;

&lt;p&gt;My time in grad school did introduce me to something else I enjoyed: CODING!!!! I was able to take a course in Python that introduced me to computational programming and my first higher-level language. The professor was super cool and this ended up being my favorite class at UW. In hindsight, this should have raised some alarm bells but live and learn ¯_(ツ)_/¯ &lt;/p&gt;

&lt;p&gt;So I knew I wanted to spend some time coding to confirm that I enjoyed it enough to do it year-round. I was already living in Seattle and looked around ultimately going with Flatiron because it felt right. Not knowing much about web development or coding outside of school, I figured this experience would introduce me to a whole new world.&lt;/p&gt;

&lt;p&gt;And I'm so glad I did! This program has been a great experience for me and a fun way to start of 2020.&lt;/p&gt;

</description>
      <category>beginners</category>
    </item>
  </channel>
</rss>
