<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lauren Wszolek on Medium]]></title>
        <description><![CDATA[Stories by Lauren Wszolek on Medium]]></description>
        <link>https://medium.com/@lwszolek?source=rss-40aa3d5f325f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AOTgwEElNcpRNKUrzP0irg.jpeg</url>
            <title>Stories by Lauren Wszolek on Medium</title>
            <link>https://medium.com/@lwszolek?source=rss-40aa3d5f325f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 01:31:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lwszolek/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Module Inheritance Part I: Include and Prepend — Ruby 2.4.1]]></title>
            <link>https://medium.com/@lwszolek/module-inheritance-part-i-include-and-prepend-ruby-2-4-1-a07d287ba83d?source=rss-40aa3d5f325f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a07d287ba83d</guid>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Lauren Wszolek]]></dc:creator>
            <pubDate>Tue, 09 May 2017 06:01:32 GMT</pubDate>
            <atom:updated>2017-05-09T06:01:32.504Z</atom:updated>
            <content:encoded><![CDATA[<p>I want to look at some less obvious behavior when usinginclude, prepend, and extend for mixins and modules. This turned out quite long, so I will split it into two parts, one for include and prepend, and the second for extend (who, between you and me, is the real trickster of the bunch).</p><p>I will skip the whole misleading “include adds methods as instance methods, and extend adds methods as class methods” bit, but assume that in general, you more or less grok the explanation given about these things from 99% of Stack Overflow questions on the topic. (I’ll probably come back and edit this section to summarize this knowledge rather than just reference it.). On to the edge cases!</p><p>First, let’s create some classes for demonstrative purposes:</p><pre>class Animal<br>  def make_sound<br>    &quot;the sound of silence&quot;<br>  end<br>end</pre><pre>module Cat<br>  def make_sound<br>    &quot;meow&quot;<br>  end</pre><pre>  def pet<br>    &quot;purrrr&quot;<br>  end<br>end</pre><pre>module Dog<br>  def make_sound<br>    &quot;woof&quot;<br>  end</pre><pre>  def pet<br>    &quot;wags tail&quot;<br>  end<br>end</pre><p>Adorable. Let’s take a look at include, the one people more or less get right.</p><h3>Include</h3><p>include will add the instance methods in the module into the existing class as instance methods on that class. This behavior is well documented elsewhere. I want to look at some edge cases. What happens if there are methods with the same name in the base class and the module? Which definition wins?</p><h4>include: Method Shadowing</h4><p>Dog and Animal both have methods named make_sound. Let’s see what happens if we include Dog into Animal in the class definition:</p><pre>class Animal<br>  include Dog         # &lt;&lt; newly added</pre><pre>  def make_sound<br>  [...]<br>end</pre><p>Now in console:</p><pre>&gt; dog = Animal.new <br>=&gt; #&lt;Animal:0x007f939d818f70&gt;</pre><pre>&gt; dog.pet<br>=&gt; wags tail               # inherited from Dog</pre><pre>&gt; dog.make_sound   <br>=&gt; the sound of silence    # this is the sound from Animal</pre><p>When a module is included, it is added to the lookup chain <em>directly</em> <em>after</em> the current class. It becomes the immediate superclass/parent/ancestor, meaning the module does not overwrite methods in the class it is being included into.</p><pre>&gt; dog.class.ancestors <br>=&gt; [Animal, Dog, Object, Kernel, BasicObject]</pre><p>As you can see, Dog is in the inheritance chain after Animal, so the method definition lookup will never reach the definition of make_sound that is defined in Dog.</p><h4>include: Inheritance Chain</h4><p>It is worth specifically noting that the inheritance chain will be updated in the order the include statements are processed, and the new ancestor is always made the immediate ancestor.</p><p>Let’s also include Cat after we include Dog and see this in action.</p><pre>class Animal<br>  include Dog <br>  include Cat         # &lt;&lt; newly added<br>  [...]<br>end</pre><p>What have you got for me, console?</p><pre>&gt; mystery = Animal.new<br>=&gt; #&lt;Animal:0x007f939d818f70&gt;</pre><pre>&gt; mystery.pet<br>=&gt; purrrr                # this is pet from Cat, not Dog</pre><pre>&gt; mystery.class.ancestors<br>=&gt; [Animal, Cat, Dog, Object, Kernel, BasicObject]</pre><p>As you can see, Cat, though it was physically a line lower in the code and therefore “later”, became the immediate ancestor when that line of code was processed, pushing Dog up the chain. When we look up the method pet, we check Animal and find nothing, then look at Cat, where we find the pet method and stop.</p><h4>include: Class Methods</h4><p>Class methods, as usual, are not added to the base class when includeing a module. Let’s add a class method to Dog called is_good_girl and have it return a class variable set to true (because all doggies are good girls yes they are).</p><pre>module Dog<br>  @@good_girl = true      # &lt;&lt; newly added</pre><pre>  def self.is_good_girl   # &lt;&lt; newly added<br>    @@good_girl           # &lt;&lt; newly added<br>  end                     # &lt;&lt; newly added</pre><pre>  [...]<br>end</pre><pre>class Animal<br>  include Dog<br>  [...]                   # not including Cat anymore<br>end</pre><p>Animal is still including Dog (but not Cat this time), so let’s see what we get when we try to access is_good_girl:</p><pre># definitely can&#39;t access from an instance</pre><pre>&gt; dog = Animal.new <br>=&gt; #&lt;Animal:0x007f939d818f70&gt;</pre><pre>&gt; dog.is_good_girl <br>=&gt; NoMethodError: undefined method `is_good_girl&#39; for #&lt;Animal:0x007f977511b688&gt;</pre><pre># also can&#39;t access it from the class</pre><pre>&gt; Animal.is_good_girl <br>=&gt; NoMethodError: undefined method `is_good_girl&#39; for Animal:Class</pre><pre># can access from the module directly, however</pre><pre>&gt; Dog.is_good_girl<br>=&gt; true</pre><p>As expected, the base class did not inherit the class methods. However, not so with class variables! Animal will receive the class variables defined in the included module Dog.</p><h4>include: Class Variables</h4><p>Remember, def self.is_good_girl is a class method, and @@good_girl is a class variable set to true on Dog.</p><pre># obviously this does not work, we did not define an accessor</pre><pre>&gt; Animal.good_girl<br>=&gt; NoMethodError: undefined method `good_girl&#39; for Animal:Class</pre><pre># this, however, works</pre><pre>&gt; Animal.class_variable_get(&quot;@@good_girl&quot;)<br>=&gt; true</pre><p>Because we can still access the class variables, we can still get at them if we wrap them in accessor methods in either the Dog module or the Animal class itself. Let’s change the example from above slightly to show this:</p><pre>module Dog<br>  @@good_girl = true      </pre><pre>def is_good_girl         # &lt;&lt; changed method from class to instance <br>  @@good_girl           <br>end                     </pre><pre>[...]<br>end</pre><pre>class Animal<br>  include Dog<br>  [...]                   <br>end</pre><p>Let’s check in console:</p><pre>&gt; dog = Animal.new <br>=&gt; #&lt;Animal:0x007f939d818f70&gt;</pre><pre>&gt; dog.is_good_girl <br>=&gt; true</pre><p>If this were javascript, I’d likely think something like “Dog has a closure on @@good_girl”, but class variables are agents of chaos. Let’s change things around a bit.</p><h4>include: Class Variable Shadowing</h4><pre>module Dog<br>  @@good_girl = true</pre><pre>  def is_good_girl<br>    @@good_girl<br>  end<br>  [...]<br>end</pre><pre>class Animal<br>  include Dog</pre><pre>  @@good_girl = false    # impossible, just an example<br>  [...]<br>end</pre><p>If this were javascript, running dog.is_good_girl would continue to return true.</p><pre>&gt; dog.is_good_girl<br>=&gt; false                 # actual output - it is not true</pre><p>As you might have detected, this is Ruby and not javascript, so what instead will happen is:</p><ul><li>we look for the method is_good_girl on the current instance (dog of class Animal).</li><li>We do not find it on Animal, so we look up the ancestor chain to Dog, and do find is_good_girl.</li><li>Now in the method, we need to find @@good_girl. We start over from the original call site: dog.is_good_girl and check Animal for @@good_girl, which we find and has a value of false (once again, impossible that the dog is not a good girl, but for the purposes of the exercise, we will allow it).</li></ul><p>The class variable behavior described is not <em>exactly</em> special, as it is the same functionality offered by traditional Ruby subclassing[<a href="https://stackoverflow.com/questions/1251352/ruby-inherit-code-that-works-with-class-variables">1</a>], but I think class variable behavior so surprising that I need to type it out as many times as possible so I can remember why there is rarely a justification good enough to use one. So in summary, include more or less works like normal inheritance, as long as you remember the bit about the Inheritance Chain pushing each included module up the chain at the time of inclusion.</p><h4>include: Instance Variables?!</h4><p>Modules don’t have instances, and so they don’t have instance variables, right? Remember how we were just talking about how you can access a module’s class variables if the module defined an accessor? What happens if it’s an instance variable and not a class variable?</p><pre>module Bird<br>  @food = &quot;birdseed&quot;         # instance variable</pre><pre>  def get_food               # instance method to access @food<br>    @food<br>  end</pre><pre>  def self.class_get_food    # class method to access @food<br>    @food<br>  end<br>end</pre><pre>class Animal<br>  include Bird               # only including Bird this time<br>  [...]<br>end</pre><p>Let’s check console:</p><pre>&gt; bird = Animal.new<br>=&gt; #&lt;Animal:0x007ffcec86a998&gt;</pre><pre># instance variables from the module are not set in the inheriting <br># class</pre><pre>&gt; bird.food<br>=&gt; NoMethodError: undefined method `food&#39; for #&lt;Animal:0x007f827926ca48&gt;</pre><pre># we can run the accessor instance method, but still can&#39;t access<br># the instance variable in the module</pre><pre>&gt; bird.get_food<br>=&gt; nil</pre><pre># no this is just silly why am I including this</pre><pre>&gt; Bird.get_food<br>=&gt; NoMethodError: undefined method `get_food&#39; for Bird:Module</pre><pre># however, this DOES return the instance variable</pre><pre>&gt; Bird.class_get_food<br>=&gt; birdseed</pre><p>So… they’re like local variables? No, not that either.</p><pre>module Snake<br>  def self.num_legs         # class accessor<br>    @leg_count              # instance variable <br>  end</pre><pre>  def self.num_legs=(count) # class writer<br>    @leg_count = count      <br>  end<br>end</pre><pre>class Animal<br>  include Snake             # only including Snake<br>  [...]<br>end</pre><p>If instance variables in modules behave like local variables, then we shouldn’t be able to set and retrieve values.</p><pre>&gt; Snake.num_legs<br>=&gt; nil</pre><pre>&gt; Snake.num_legs = 0<br>=&gt; 0</pre><pre>&gt; Snake.num_legs<br>=&gt; 0</pre><p>So not local variables, which would have been scoped to their reader/writer methods, but since Modules don’t have instances, they can’t really be true instance variables either.</p><p>¯\_(ツ)_/¯ [<a href="https://stackoverflow.com/questions/15478747/instance-variables-in-modules">2</a>]</p><p>Now let’s look at prepend. This will be short, I promise.</p><h3>Prepend</h3><p>We are going to use the same setup as above, except this time I am going to prepend Dog instead of include:</p><pre>class Animal<br>  prepend Dog  # &lt;&lt; newly added - it&#39;s prepend!</pre><pre>def make_sound<br>  [...]<br>end</pre><p>Now let’s see what happens when we try to access make_sound:</p><pre>&gt; dog = Animal.new<br>=&gt; #&lt;Animal:0x007fd4b1024c60&gt;</pre><pre>&gt; dog.make_sound<br>=&gt; woof                    # this time we got the response from Dog</pre><pre>&gt; dog.class.ancestors<br>=&gt; [Dog, Animal, Object, Kernel, BasicObject]</pre><p>Oho! So Dog now precedes Animal in the lookup chain! If you take that into account and reread everything on include, you get it. <a href="http://gshutler.com/2013/04/ruby-2-module-prepend/">There’s some additional stuff with memoization that’s worth reading about</a> [<a href="http://gshutler.com/2013/04/ruby-2-module-prepend/">3</a>] but that’s unlikely to be useful for most people.</p><p>That’s it for include and prepend. Please let me know if I have errors or have missed any noteworthy facets of either method. Next time, I will cover next bit that seems to cause the most confusion: extend.</p><h4>sources:</h4><p>[1] <a href="https://stackoverflow.com/questions/1251352/ruby-inherit-code-that-works-with-class-variables">https://stackoverflow.com/questions/1251352/ruby-inherit-code-that-works-with-class-variables</a></p><p>[2] <a href="https://stackoverflow.com/questions/15478747/instance-variables-in-modules">https://stackoverflow.com/questions/15478747/instance-variables-in-modules</a></p><p>[3] <a href="http://gshutler.com/2013/04/ruby-2-module-prepend/">http://gshutler.com/2013/04/ruby-2-module-prepend/</a></p><h4>addtl awesome reference — actually goes into source code:</h4><p><a href="https://ernie.io/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/">https://ernie.io/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/</a></p><p>note on sources: I used many different articles/doc pages, but I am citing those with what I found to be the most clear explanations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a07d287ba83d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Once you see arrow function abuse, you can’t unsee it]]></title>
            <link>https://medium.com/@lwszolek/once-you-see-arrow-function-abuse-you-cant-unsee-it-9ca5f4630ab8?source=rss-40aa3d5f325f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ca5f4630ab8</guid>
            <category><![CDATA[arrow-functions]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Lauren Wszolek]]></dc:creator>
            <pubDate>Fri, 02 Dec 2016 05:30:41 GMT</pubDate>
            <atom:updated>2016-12-02T05:38:33.483Z</atom:updated>
            <content:encoded><![CDATA[<p><em>“Don’t trust children with edge tools. Don’t trust man, great God, with more power than he has until he has learned to use that little better. What a hell we should make of the world if we could do what we would!” <br>― </em><a href="https://books.google.com/books?id=YvyUAwAAQBAJ&amp;pg=PA55&amp;lpg=PA55&amp;dq=%22Don%27t+trust+children+with+edge+tools.%22&amp;source=bl&amp;ots=HwsZn-KmUf&amp;sig=9EOlraIsIiZfYn1AhtBL-bcC05c&amp;hl=en&amp;sa=X&amp;ved=0ahUKEwjdocWD4dTQAhXGjFQKHQKECp4Q6AEISTAL#v=onepage&amp;q=%22Don&#39;t%20trust%20children%20with%20edge%20tools.%22&amp;f=false"><strong><em>Ralph Waldo Emerson</em></strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jAiFljApvYVqYXVKkOY49Q.jpeg" /><figcaption>There are many practical applications of massive trucks, but they’re not suited for all driving tasks</figcaption></figure><p>Perhaps Emerson might have said “<em>What a hell we should make of this app if we could do what we would in JavaScript!</em>” if he had ever visited Stack Overflow and read through code samples. JavaScript is a tremendously flexible language and tasks can be completed in a variety of ways — but these ways do not have to be equivalently “good”, even if they have similar apparent results. Purposeful, deliberate code makes a maintainable app that is easier to collaborate in: most would prefer to avoid working in a codebase where the “why” of code decisions is weak or missing.</p><p>This particular question is not special, it is just an example:</p><p><a href="http://stackoverflow.com/questions/1063007/how-to-sort-an-array-of-integers-correctly">How to sort an array of integers correctly</a></p><blockquote>This code can be shortened using an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow Function</a>. numberArray.sort((a, b) =&gt; (a - b));Yay! I think this is close to the out-of-the-box way. <strong>Note: check if your JS engine supports Arrow Functions.</strong> – <a href="http://stackoverflow.com/users/4510033/k">K. _</a> <a href="http://stackoverflow.com/questions/1063007/how-to-sort-an-array-of-integers-correctly#comment56723716_1063027">Dec 28 &#39;15 at 9:41</a></blockquote><p>STOP!</p><p>This is abuse of the poor arrows, calling them from their comfortable home in the ether to make them do a job that is beneath them. This is like needing to buy a car to take your kids to soccer practice and buying a 16 wheeler — I guess it works, but you’re doing it weird. People’ll start asking you about your abrupt career change to trucker and barely notice you also happen to drive your kids around in it (and they’re going to wonder if it’s safe). Technically, you’ve solved the problem, but I’d argue it was a poor choice.</p><p>Writing a sort method in this way is using a <em>side effect</em> of the arrow syntax to cut out the words function and return, without actually using the arrow function’s true purpose of passing this. I would strongly discourage others from using an arrow function here, as it implies there is some this context passing happening, but there isn’t.</p><p>Use arrow functions only when you need to pass this. Don’t use it as a “shorter” form of standard functions definitions, because it simply isn’t the same, and communicating intent is important.</p><p>Also: why do so many seem to miss that sort() performs its actions in place? There is no need to say myarr = myarr.sort(), the original myarr will be sorted as soon as you call sort on it…but I think even imaginary frontend coder Emerson would let that one slide.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ca5f4630ab8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The worst ‘javascript interview prep’ article ever]]></title>
            <link>https://medium.com/@lwszolek/the-worst-javascript-interview-prep-article-ever-528fd03bda98?source=rss-40aa3d5f325f------2</link>
            <guid isPermaLink="false">https://medium.com/p/528fd03bda98</guid>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Lauren Wszolek]]></dc:creator>
            <pubDate>Wed, 30 Nov 2016 06:13:51 GMT</pubDate>
            <atom:updated>2016-12-02T00:50:20.690Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m linking this here, but you should not believe any of these lies.</p><p><a href="https://www.codementor.io/javascript/tutorial/21-essential-javascript-tech-interview-practice-questions-answers">21 Essential JavaScript Interview Questions | Codementor</a></p><p>Question 1…. I mean, ok. It’s not a great answer, but it’s not deceiving you the way question 2 is.</p><p>I’ll cut and paste question 2 here for you so you don’t need to dirty your browser history:</p><blockquote>Question 2</blockquote><blockquote>What will be the output of the code below?</blockquote><blockquote>var y = 1;<br> if (function f(){}) {<br> y += typeof f;<br> }<br> console.log(y);</blockquote><blockquote>The output would be undefined. The if condition statement evaluates using eval, so eval(function f(){}) returns function f(){} (which is true). Therefore, inside the ifstatement, executing typeof f returns undefined because the if statement code executes at run time, and the statement inside the if condition is evaluated during run time.</blockquote><blockquote>var k = 1;<br> if (1) {<br> eval(function foo(){});<br> k += typeof foo;<br> }<br> console.log(k);</blockquote><blockquote>The code above will also output undefined.</blockquote><blockquote>var k = 1;<br> if (1) {<br> function foo(){};<br> k += typeof foo;<br> }<br> console.log(k); // output function</blockquote><p>Oh my god, no. I felt horror that anyone could use this as a resource to better understand javascript — this isn’t even the first time someone lied to me in a javascript tutorial today!</p><p>Part of this is true: if you run that first code snippet, you will indeed get undefined. But not for the reasons listed, not even close. At first, I was confused — sure it doesn’t work, but why not? If conditional expressions don’t allow variable declarations, but they allow assignments, function calls, etc., why not this? And why does it pass into the loop at all?</p><p>Here’s my response (with better formatting &amp; sources cited at the end) . It took about two hours until I was totally satisfied, dipping into the es6 spec and my first trip into the v8 codebase (no answers, but it was fun to poke around):</p><p>Hi,</p><p>I am only on question 2, but there are serious errors.</p><p>First, let’s say eval <em>was</em> being used inside of an if statement (it is not): the reasoning is faulty. eval() only interprets strings — if anything else is passed in, it simply returns it. It is not evaluated. So because it was not evaluated, foo remains undefined. It has nothing to do with runtime. If eval was happening here, then it would make sense we entered the loop — we got back a non falsey value, ie function foo(){}, yet it was not evaluated, so trying to call foo would result in an error.</p><p>so eval(function foo(){}) returns function foo(){} without evaluating it.</p><p>The given explanation also seems to imply that ‘eval’-ing something means it would not enter the current scope, this is not true. eval-uated strings immediately enter the scope (use with caution). If we had done instead:</p><p>eval(“function foo(){}”) we would have access to foo by name within the entire scope the eval occurred.</p><p>However, eval is not used. Let’s revisit the code snippet and see what’s really happening:</p><p>if ( function foo(){} ) { whatever }</p><p>if statements accept an <strong>expression</strong> as argument/condition. I made that bold so it’s apparent this is a special term and not the colloquial concept of an expression. function foo(){} can either be a <strong>function declaration</strong>, or the same snippet of code can be a <strong>function expression</strong>, depending on where the text appears in the line of code. <strong>Function declarations</strong> occur when function is the <em>first text on the line and nothing precedes it</em>, meaning it is defined in the current scope. Here is a function declaration:</p><p>function foo() {}</p><p>However, function foo() {} is a <strong>function expression</strong> in this context. if <em>takes only expressions. </em>Declarations are not expressions. You can’t say if(var foo = 12), because var foo = 12 is not an expression. So when this code is run, it is creating function foo(){} as an expression, which is valid syntax in an if statement. Names are not bound to the current scope with function expressions, they are only bound within the function itself. function foo(){} is an empty function — so this name is never used, and the function becomes inaccessible immediately after this section of code is run.</p><p>sources:</p><p><em>eval returns any non-string argument without processing it:</em><br><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval</a><br><a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=98">http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=98</a></p><p><em>if statements accept expressions:</em><br><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else</a></p><p><em>named function expressions have their name scoped to within themselves :</em><br><a href="https://github.com/getify/You-Dont-Know-JS/blob/31e1d4ff600d88cc2ce243903ab8a3a9d15cce15/scope%20%26%20closures/ch3.md#functions-as-scopes">https://github.com/getify/You-Dont-Know-JS/blob/31e1d4ff600d88cc2ce243903ab8a3a9d15cce15/scope%20%26%20closures/ch3.md#functions-as-scopes</a></p><p>I can fix the rest of the issues if you send me whatever paycheck they gave you for writing this.</p><p>Maybe I’ll do the rest, because wow does it look like there are a lot of errors in the rest of the questions. So many, it almost seems like an anti-javascript plant trying to misinform and frustrate people…. Though, like my last comment says, I kinda want to be paid for doing your work properly.</p><p>Actually, Mr UI Engineering Lead, maybe I should just get your job: I am in the market.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=528fd03bda98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[uniquing an array in javascript & finding a love of coding challenges]]></title>
            <link>https://medium.com/@lwszolek/uniquing-an-array-in-javascript-finding-a-love-of-coding-challenges-d66308438f03?source=rss-40aa3d5f325f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d66308438f03</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Lauren Wszolek]]></dc:creator>
            <pubDate>Tue, 29 Nov 2016 06:34:03 GMT</pubDate>
            <atom:updated>2016-11-29T06:54:30.225Z</atom:updated>
            <content:encoded><![CDATA[<p>While working on a H<a href="https://www.hackerrank.com/challenges/between-two-sets">ackerRank problem</a>, I wanted to get the unique values for an array of integers. This is a tremendously common problem, and one I’ve never had to solve on my own before in JavaScript. Every frontend app I’ve ever worked on uses the <a href="http://underscorejs.org/">underscore library</a>, where this (and other scenarios) are solved problems. I was halfway to typing uniq before I realized my error. As a coder, I am often only too glad to offload solved problems to a common library and move my brain to focus on the … ah…. <em>unique</em> challenges of my current task, but this ended up being a fun exploration.</p><p>I found this cute solution:</p><pre>uniqueArr = maybeNotUniqueArr.filter(function(item, index, arr){ arr.indexOf(item) == index;});</pre><p>A bit easier on the eyes than a hash lookup, I think, but only one of many possible solutions, each with its own strengths and limitations. After turning it over in my brain, I turned to google, and eventually I landed on <a href="http://stackoverflow.com/a/9229821/6739297">this rather nice Stack Overflow answer</a> regarding some solutions. After I submit this, I’m going to run some <a href="https://jsperf.com/">jsperf</a> tests to see how the options compare</p><p>This brings me to the first thing I like about coding challenges on HackerRank (or other <a href="https://www.codewars.com/">coding</a> <a href="http://codekata.com/">challenge</a> <a href="https://www.coderbyte.com/">site</a> <a href="https://www.codeeval.com/">of</a> <a href="https://www.codingame.com/start">your</a> <a href="https://www.interviewcake.com/">choice</a>):</p><h3>Exploring Solutions From Unusual Angles</h3><p>I usually spend most of my “solving” time pondering multiple possible solutions, reading over Mozilla JavaScript docs, and digging more into the language. I moved from the backend to the front and began writing JavaScript around two years ago, where all of that time was spent in a handful of repos in the same org, where there was little flexibility and room for solutions that didn’t fit the normal “way” of things, where there was disincentive to use methods or algorithms outside of the well-understood.</p><p>When I’m not constrained by mandated libraries or coding patterns (my last position forbade the usage of JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promises</a>, if you can believe that), I can look at the problem from multiple angles and mull over the differing dimensions. I usually have an immediate idea or two for an answer, but I generally start by pulling up the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects">built in objects page</a> on the Mozilla docs and scanning the list, clicking through and reading over methods and properties, and making short, psuedo-code notes on a whiteboard, then testing different ideas out in browser console or in the HackerRank console. Referring back to uniquing arrays: I never thought to use Set, as I’ve never had a use for it in my everyday coding. Here is the perfect opportunity to dig into them! There are many ways to uniq an array —and I only ever learned one: depend on someone else’s library. I’ll write a different blog post about that later.</p><p>I am also enjoying the chance to actually go for once for those oh-so-clever solutions I would be unlikely to use in real prod code: these clever solutions often depend on a perfectly defined problem space with perfectly defined requirements so I can write code I’ll never have to maintain and no one else will need to read. Totally fine for a coding challenge! It also lets my brain stretch a little, since I get to define the “best” solution — HackerRank doesn’t seem to care what I write as long as it outputs the expected results. One of my solutions to a previous problem used String.prototype.charCodeAt(): when have I ever even considered using that? Which brings me to my second point:</p><h3>Solving Complex Problems is Fun</h3><p>My biggest problem with interview questions/coding challenges has been that they rarely represent real problem spaces, and so the answers tend to be simplistic and not particularly useful when tackling real problems in a real application to be used by real people. Really, what are the actual frontend problems that need to be solved? 90% of actual coding work is designing a system, interpreting and processing input, writing tests, modifying workflows, interfacing with APIs, cacheing and session management, etc etc.</p><p>However, I have found a measure of pure joy turning the lights back on in the dark parts of my brain where my love of math has too often gathered dust since college and it was determined number theory didn’t have many practical uses when job hunting. I haven’t been doing these coding challenges consistently for very long, and I’ve found the sheer impracticality of the situations to be refreshing. The problem I linked to above was the first from the site where I needed to actually whiteboard out a solution, where my brain instinctively knew I needed to compute the least common multiple of set A, even if I struggled to remember the phrase “least common multiple”. Ah, sweet algebra, I have missed you. What a contrived problem, and yet how fun to solve it! Almost like the olden days of writing out proofs.</p><p>These problems are complex for the sake of complexity, and not because the requirements are a best guess at approximating a problem space, and so on to reason number 3 why I enjoy coding challenges:</p><h3>Just Getting to Write Some Code</h3><p>Going back to what I was saying earlier, these perfectly defined problems do not (or have not so far, at least) represented anything close to a real world problem, and as such, the solutions they desire depend on nothing but what is immediately given. My job might be as an engineer, but how much of my day at the office is actually devoted to straight coding? Very little. So much of the actual work is meetings, planning, requirements gathering, requirements clarifications, writing or fixing tests, code reviews, answering emails, reading documentation, writing documentation, and so on. The vast majority of my time and skills is not used in sitting at my desk and writing code undisturbed. There is something wonderfully pure and satisfying about having a contained problem that needs nothing from me except code, where my only contribution is code, where the messy parts of life that necessarily filter into every project have no place. Simple and satisfying.</p><p>I began doing online coding challenges as a way to supplement the projects I am working on and theory books I am reading to prepare myself for the inevitable “traverse a binary tree” interview questions, but I’ve found something much more satisfying, and hopefully also found a habit I’ll keep for years to come.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d66308438f03" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>