<?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>Forem: Lost Semicolon 💻🖱</title>
    <description>The latest articles on Forem by Lost Semicolon 💻🖱 (@lost_semicolon).</description>
    <link>https://forem.com/lost_semicolon</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%2F106512%2F46e29307-7bab-41aa-9f87-0d902bc4cd96.jpg</url>
      <title>Forem: Lost Semicolon 💻🖱</title>
      <link>https://forem.com/lost_semicolon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lost_semicolon"/>
    <language>en</language>
    <item>
      <title>The big secret to being consistent 🤫</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Mon, 11 Apr 2022 13:46:47 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/the-big-secret-to-being-consistent-b2h</link>
      <guid>https://forem.com/lost_semicolon/the-big-secret-to-being-consistent-b2h</guid>
      <description>&lt;p&gt;Today marks my 100 days of Duolingo learning - it is also 100 days since the 1st of January!&lt;/p&gt;

&lt;p&gt;Three months ago all I could say was “I EAT APPLES” but now I can probably fumble my way to ask for the bill. I can also proudly express that I write letters on the beach (I don’t do that, but the potential to do so is there if the occasion ever presented itself and I had to tell someone about it). Even yesterday I caught some Spanish words on the recently streamed “Yo soy Georgina” - so you could say I will be pro in no time.&lt;/p&gt;

&lt;p&gt;But, I have never been a type to stick to something daily, but this time I have - so what was different?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Firstly, I picked something I wanted to do. I always wanted to learn Spanish but I wasn’t sure it was the right “choice”. Were there other languages which were more useful to learn? Maybe bring me more income or job prospects? I used to do German and Japanese, should I not just build on those? But once i put those questions aside I could actually concentrate on learning how to book a table for 2 on my imaginary trip before bed each night. And it is good albeit sometimes frustrating fun.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Secondly, and probably most importantly, Duolingo lets you show up everyday in whatever way you can. One lesson is roughly 16 little exercises and you can do as little or as many of them as you can. Don’t want to do new lessons? You can go over your mistakes.&lt;br&gt;
Don’t have time to do that? That’s okay, there are short stories you can do instead. It is the habit of doing it everyday that is more important than the volume you do on the daily.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Thirdly, Duolingo let’s you fail without too much punishment. It allows you to not loose your streak if you miss a day every once in a while. The app focuses on getting you back on track as soon as possible and so you do not get the dread of “ i just lost my X day streak” and removes the “ What is the point of getting back to it now”.&lt;br&gt;
Will I reach my 365 day streak? Time will tell. But this journey showed how much I can achieve when I show up without expectations of being perfect. And to look back and acknowledge where I am, because looking back, that starting line is not even in sight anymore.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy learning !&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>career</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Get last part of the url</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Thu, 30 Dec 2021 16:41:05 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/get-last-part-of-the-url-3nna</link>
      <guid>https://forem.com/lost_semicolon/get-last-part-of-the-url-3nna</guid>
      <description>&lt;p&gt;In js, you can use &lt;code&gt;url.substring(url.lastIndexOf('/') + 1)&lt;/code&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Should you read "Don't make me think" by Steve Krug?</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Sun, 31 Oct 2021 13:56:20 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/should-you-read-dont-make-me-think-by-steve-krug-336g</link>
      <guid>https://forem.com/lost_semicolon/should-you-read-dont-make-me-think-by-steve-krug-336g</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SVOw4YDa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://kbimages1-a.akamaihd.net/8f24a6ca-b98d-4bc3-a6ef-e1c2482480a6/1200/1200/False/don-t-make-me-think-revisited-1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SVOw4YDa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://kbimages1-a.akamaihd.net/8f24a6ca-b98d-4bc3-a6ef-e1c2482480a6/1200/1200/False/don-t-make-me-think-revisited-1.jpg" alt="Book cover" width="880" height="1130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;TLDR: Yes, Its a short, well written and insightful book with messages that still stand true today.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Review
&lt;/h3&gt;

&lt;p&gt;"Don't Make Me Think" is a simple and fun book about designing web pages written by a usability consultant Steve Krug. I picked it up as it was short, full of illustrations and most importantly it seemed like an entertaining read about a topic I didn't really give much thought to previously.  I can't be the only one not spending my time thinking about breadcrumbs - some ducks might disagree though(1). &lt;/p&gt;

&lt;p&gt;The book is filled with simple concepts, explained well and without buzzwords or hype. Heck, even Steve manages to divide the usual business into "Hype" and "craft" folk and identifies himself as the latter. Maybe this is why his book is so simple. Or maybe it is because the book is written in a way in which follows his definition of usability:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"A person of average (or even below average) ability and experience can figure out how to use the thing to accomplish something without it being more trouble than it’s worth"&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;It's funny, that almost 7 years since the revisited edition, even though the world of the web and mobile has changed so much, the base concept still remains the same:  Make your product achieve a goal and simply. &lt;/p&gt;

&lt;p&gt;Apart from the more obvious design tips like the importance of visual hierarchies or omitting useless words, Steve also talks about some general behavioural lessons whether it is from users or your managers. I think this is why I liked it so much - He doesn't just give you a tick list of things you can do to make your website or app more usable but talks about how there is no average user, how to be better at continuous usability testing and why people do what they do.&lt;/p&gt;

&lt;h3&gt;
  
  
  My 3 things
&lt;/h3&gt;

&lt;p&gt;With that in mind, My 3 favourite takeaways from the book are: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;People pick the first "good enough option" and muddle through. It is highly unlikely a user will read instructions or help text.&lt;/li&gt;
&lt;li&gt;Use conventions and don't reinvent the wheel unless you will make something much clearer. Clarity trumps consistency. &lt;/li&gt;
&lt;li&gt;A good shared resource will be destroyed by overuse, if it is not managed. Think the front page of a website.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Negatives
&lt;/h2&gt;

&lt;p&gt;As for the negatives.... I think the mobile experience has changed so much, It deserves more space. The revisited book came out in 2014, just as the era of mobile was getting into the big swing of things.  &lt;/p&gt;

&lt;h2&gt;
  
  
  So.... should you read it?
&lt;/h2&gt;

&lt;p&gt;Yes. I would absolutely recommend the book  and I think it will be one I come back to again and again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to buy
&lt;/h2&gt;

&lt;p&gt;You know the green shpiel → Check if your local library has a copy of the book, if not buy books locally or buy them 2nd hand : &lt;a href="https://www.abebooks.co.uk/servlet/BookDetailsPL?bi=31017851480&amp;amp;searchurl=an%3Dsteve%2Bkrug%26sortby%3D17&amp;amp;cm_sp=snippet-_-srp1-_-title8"&gt;https://www.abebooks.co.uk/servlet/BookDetailsPL?bi=31017851480&amp;amp;searchurl=an%3Dsteve%2Bkrug%26sortby%3D17&amp;amp;cm_sp=snippet-&lt;em&gt;-srp1-&lt;/em&gt;-title8&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Footnotes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;please don't feed  bread  to ducks, its bad for them.)&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>todayilearned</category>
      <category>frontend</category>
    </item>
    <item>
      <title>What's your type? A short guide to data typing. </title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Mon, 16 Nov 2020 18:56:43 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/what-s-your-type-a-short-guide-to-data-typing-1oo6</link>
      <guid>https://forem.com/lost_semicolon/what-s-your-type-a-short-guide-to-data-typing-1oo6</guid>
      <description>&lt;h2&gt;
  
  
  TLDR
&lt;/h2&gt;

&lt;p&gt;Typing - way in which computers determines different data formats.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Static Typing&lt;/strong&gt; - Type defined at compile time&lt;br&gt;
&lt;strong&gt;Dynamic Typing&lt;/strong&gt; - Type defined at run time&lt;br&gt;
&lt;strong&gt;Weakly Typed&lt;/strong&gt; - Variables can change type at run time&lt;br&gt;
&lt;strong&gt;Strongly Typed&lt;/strong&gt; - Variables cannot change type at run time&lt;/p&gt;
&lt;h2&gt;
  
  
  Read on....
&lt;/h2&gt;

&lt;p&gt;When I first stated learning development, I used to think of "typing" as "typing on a keyboard" rather than "data typing" &lt;br&gt;
which is why everything was a little bit more confusing at the start. You live and learn tho. &lt;/p&gt;
&lt;h1&gt;
  
  
  What is typing?
&lt;/h1&gt;

&lt;p&gt;Data typing is a way of describing the type of data we are using. For example, we know that a boolean can only be True or False, or 0 and 1. &lt;br&gt;
This process allows the compilers to determine the required memory to hold data and ensure that the program can be run with no type errors. &lt;/p&gt;
&lt;h1&gt;
  
  
  Types, types, types
&lt;/h1&gt;
&lt;h3&gt;
  
  
  Static and Dynamic typing
&lt;/h3&gt;

&lt;p&gt;If we define the type of data when we declare a new variable such as :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Java&lt;/span&gt;
&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then this is known as &lt;strong&gt;Static Typing&lt;/strong&gt; where type is explicitly typed before the compiler. Languages such Java or C# as do this.&lt;br&gt;
Attempts to re-assign the variable type will result in an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Java&lt;/span&gt;
&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"naw, mate"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//compilation error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The type checking in this case, is done at &lt;em&gt;Compile Time&lt;/em&gt; ( although many IDE's will let you know ahead of time, they are good that way).&lt;/p&gt;

&lt;p&gt;If we do not need to specify the type which we want our data to be, it is determined at run time. The language then has &lt;strong&gt;Dynamic Typing&lt;/strong&gt; and examples include JavaScript or Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//javascript&lt;/span&gt;
&lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Strongly and Weakly typed languages
&lt;/h3&gt;

&lt;p&gt;Some languages allow you to re-assign the type a variable can hold at runtime - for example Javascript. This a quality of &lt;strong&gt;weakly typed&lt;/strong&gt; languages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//javascript&lt;/span&gt;
&lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where as in others, this is not the case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//error: incompatible types: String cannot be converted to boolean&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Some flexible languages
&lt;/h3&gt;

&lt;p&gt;Sometimes, languages are super flexible, like Go. Whilst being usually considered a strongly typed static language, it allows the compiler to determine the type, but once its set, you cannot change it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="n"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;

&lt;span class="c"&gt;//cannot use 1 (type untyped int) as type bool in assignment&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Is static faster than dynamic?
&lt;/h3&gt;

&lt;p&gt;In theory, yes, because the compiler doesn't need to work out what data type it needs. &lt;/p&gt;

&lt;p&gt;In practice, this is not the only way to measure performance. In &lt;a href="https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/go.html"&gt;Java vs Go comparison&lt;/a&gt;, both languages are statically and strongly typed and yet the performance varies due to a multitude of other factors. &lt;br&gt;
In addition, different languages have different use cases, and have been developed with different purposes in mind&lt;br&gt;
(whether they have kept to it 10yrs down the line, thats a different issue) and so sometimes its like comparing &lt;a href="https://benchmarksgame-team.pages.debian.net/benchmarksgame/sometimes-people-just-make-up-stuff.html"&gt;Apples and Oranges&lt;/a&gt;. &lt;/p&gt;

&lt;h1&gt;
  
  
  Should I change the type during the running of my code?
&lt;/h1&gt;

&lt;p&gt;As always, it depends. &lt;/p&gt;

&lt;p&gt;But in majority of the cases, I would argue that this is a code smell and show be avoided where possible. Typescript was created in the big part, to help JS devs eliminate type bugs!&lt;/p&gt;

&lt;p&gt;In certain cases it does make sense.&lt;/p&gt;

&lt;p&gt;Happy coding! &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
    <item>
      <title>Find the length of a loop in a linked list</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Sat, 12 Sep 2020 22:12:04 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/find-the-length-of-a-loop-in-a-linked-list-46i8</link>
      <guid>https://forem.com/lost_semicolon/find-the-length-of-a-loop-in-a-linked-list-46i8</guid>
      <description>&lt;p&gt;I have been doing some katas, to improve my coding skills.  I am now at 6kyu on &lt;a href="https://www.codewars.com/"&gt;CodeWars&lt;/a&gt;.&lt;br&gt;
This week my interesting problem was : &lt;/p&gt;

&lt;p&gt;You are given a node that is the beginning of a linked list. This list always contains a tail and a loop. Your objective is to determine the length of the loop. The loop looks like this: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SvB1QYDf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Rc6RPT5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SvB1QYDf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Rc6RPT5.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to Solve
&lt;/h2&gt;

&lt;p&gt;There are 2 parts of this question: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Figure out when you are in the loop&lt;/li&gt;
&lt;li&gt;Count the nodes in the loop &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Figure when you are in the loop
&lt;/h3&gt;

&lt;p&gt;After a quick google, I have discovered the Floyd's Cycle Detection algoritm - which, as it says, finds whether you are stuck in a loop. You can also use it to find exactly where the start of the loop is, but this is outwith the scope of this question.&lt;/p&gt;

&lt;p&gt;The basic idea is that you have 2 pointers: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one moving to the next node by 1 ( slow pointer) &lt;/li&gt;
&lt;li&gt;second pointer which moves by 2 nodes (fast pointer) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the list you are in is indeed a loop, both should meet at some point as both will be going round-and round.&lt;/p&gt;

&lt;p&gt;The code therefore is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getNodeInLoop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//problem assumes there is always going to be a loop&lt;/span&gt;
&lt;span class="c1"&gt;//so no need to check&lt;/span&gt;
   &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;fast&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; 
        &lt;span class="nx"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;slow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//move by 1&lt;/span&gt;
        &lt;span class="nx"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//move by 2&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;slow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We therefore return a &lt;em&gt;known location&lt;/em&gt; of a node in the loop. &lt;/p&gt;

&lt;h3&gt;
  
  
  Count
&lt;/h3&gt;

&lt;p&gt;We can start counting the nodes! We take our node in which both slow and fast pointers matched (in here seenNode) as treat it as the root node in the loop. We use a "pointer" variable to keep track of there we are in our while loop and "count" to count the number of nodes we have went through:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;seenNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getNodeInLoop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;pointer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;seenNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pointer&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;seenNode&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="nx"&gt;pointer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;The Full solution is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;loop_size&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;seenNode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getNodeInLoop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;pointer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;seenNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

    &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pointer&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;seenNode&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="nx"&gt;pointer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;getNodeInLoop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;//problem assumes there is always going to be a loop&lt;/span&gt;
&lt;span class="c1"&gt;//so no need to check&lt;/span&gt;
   &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;fast&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; 
        &lt;span class="nx"&gt;slow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;slow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//move by 1&lt;/span&gt;
        &lt;span class="nx"&gt;fast&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//move by 2&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;slow&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ta-dah! &lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.codewars.com/kata/52a89c2ea8ddc5547a000863"&gt;CodeWars Question&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=MFOAbpfrJ8g&amp;amp;ab_channel=HackerRank"&gt;Floyd's Cycle Detection algoritm - clear explanation on hackerrank&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;p.s I am not sure why but codewars does not like separate functions for a solution, and therefore most of my coding solutions are just written as one function.&lt;br&gt;
p.p.s As always, this is only my solution and I know there are other implementations out there. Feel free to comment your one to start a discussion :) !&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Return Boolean or Element in .filter()?</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Wed, 02 Sep 2020 19:54:35 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/return-boolean-or-element-in-filter-4mfn</link>
      <guid>https://forem.com/lost_semicolon/return-boolean-or-element-in-filter-4mfn</guid>
      <description>&lt;p&gt;I have been doing &lt;a href="http://codewars.com"&gt;codewars&lt;/a&gt; in order to improve my JS skills. I am now at 7 kyu - graduated from 8 kyu -and I have been enjoying solving programming puzzles.&lt;/p&gt;

&lt;p&gt;My recent challenge which caused me some bother concerned arrays. The task was as follows: &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Given an arrays a and b, return values from array a which are not present in array b.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Seems simple at first sight. Essentially, we require a .filter() which will return an element. Such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;arrayDiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                      &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)){&lt;/span&gt;
                        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
                 &lt;span class="p"&gt;}})&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;newArray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;However, when we run the test below, we are missing the 0 value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;assertDeepEquals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arrayDiff&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; 
&lt;span class="c1"&gt;//output is [6]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It took me a while to figure out why this was happening.&lt;br&gt;
In JavaScript, 0 can represent false and 1 can represent true. &lt;/p&gt;

&lt;p&gt;By returning the value 0, we are indivertibly returning false, telling the .filter() function that there is no match and the element shouldn't be added to the new array.&lt;/p&gt;

&lt;p&gt;Instead of returning the element, in this case, we should return a boolean.&lt;/p&gt;

&lt;p&gt;And so the solution is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;arrayDiff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  But when can I use element and not a boolean?
&lt;/h2&gt;

&lt;p&gt;You should use "element" when you would like omit anything, which may be interpreted by JS as falsey. One of these examples could be removing undefined values from an array or empty strings. &lt;/p&gt;

&lt;p&gt;Values which can be interpreted as falsy are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;false &lt;/li&gt;
&lt;li&gt;null &lt;/li&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;li&gt;0 &lt;/li&gt;
&lt;li&gt;NaN&lt;/li&gt;
&lt;li&gt;''&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Further reading:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.codewars.com/kata/523f5d21c841566fde000009/"&gt;CodeWars Cata&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"&gt;.filter() documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/23089336/array-sort-filter-with-zero-in-javascript"&gt;Helpful Stack Overflow question about it&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you enjoyed!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Why .reduce() caused me so much confusion over the past 2 days.</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Sun, 30 Aug 2020 19:03:22 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/why-reduce-caused-me-so-much-confusion-over-the-past-2-days-kp1</link>
      <guid>https://forem.com/lost_semicolon/why-reduce-caused-me-so-much-confusion-over-the-past-2-days-kp1</guid>
      <description>&lt;p&gt;This month I started doing coding katas to improve my JavaScript skills. I do puzzles and quizzes on my phone a lot anyway, and coding is not that far off solving puzzles. &lt;/p&gt;

&lt;p&gt;I am using &lt;a href="https://www.codewars.com/"&gt;Code Wars&lt;/a&gt; - the site is free, you can see other folks' solutions and there is a level system to see you progress. It also encourages you to participate in the community, which is a great mindset to install in people. &lt;/p&gt;

&lt;p&gt;I found it to be a great tool, even though the interface can be a lot and I had to familiarise myself with the ranks.&lt;/p&gt;

&lt;p&gt;I was doing a simple kata of &lt;a href="https://www.codewars.com/kata/5715eaedb436cf5606000381/train/javascript"&gt;adding arrays&lt;/a&gt;. The kata requested that, given an array of items, I had to return a sum of all positive values in the array. &lt;/p&gt;

&lt;p&gt;Initially, and I thought that adding all items in the array would be an easy task, as this can be done using the .reduce() function. But not all of the tests were passing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;positiveSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;  &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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



&lt;p&gt;When the input arrays started with a negative values, my tests failed. In a test where an array had all negative values, I would expect the value of 0 to be returned as no values would be added. However, I would be finishing up with the arr[0] value instead.&lt;/p&gt;

&lt;p&gt;Unfortunately, I have wrongly assumed that the total value (also known in js land as the &lt;em&gt;accumulator&lt;/em&gt;) started at 0. This is not the case - the accumulator starts as the first value in the array. AND the first loop starts on the 2nd item in the array (arr[1]). For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;positiveSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Total is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; and current value is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; 
  &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;  &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;testArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;//we expect 0 as all are negative values&lt;/span&gt;

&lt;span class="nx"&gt;positiveSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;testArray&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//we get -1&lt;/span&gt;

&lt;span class="c1"&gt;//Output&lt;/span&gt;
&lt;span class="c1"&gt;//Total is -1 and current value is -2&lt;/span&gt;
&lt;span class="c1"&gt;//Total is -1 and current value is -3&lt;/span&gt;
&lt;span class="c1"&gt;//Total is -1 and current value is -4&lt;/span&gt;
&lt;span class="c1"&gt;//Total is -1 and current value is -5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So, as you can see, the function is only called 4 times, with -1 being the initial accumulator value. This meant that the arrays which were starting with a negative value, would have incorrect totals.&lt;/p&gt;

&lt;p&gt;In addition to the above, when arrays were empty, I had to put in a safety check for that as well.&lt;/p&gt;

&lt;p&gt;Defeated, I have used a simple .forEach() to finish my kata - which, admittedly,  worked like a charm.&lt;/p&gt;

&lt;h1&gt;
  
  
  BUT PLOT TWIST!
&lt;/h1&gt;

&lt;p&gt;When I have looked at solutions for my fellow coders, I have realised that .reduce() method can, in fact, take an initial accumulator value!&lt;/p&gt;

&lt;p&gt;The only thing I had to correct was adding a 0 as an argument in  my reduce() function :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What does this do to iterations? Well, there is now an iteration per element in the array, starting at the 1st element (arr[0]). &lt;/p&gt;

&lt;p&gt;The problem of reductions on empty arrays was also solved this way! &lt;/p&gt;

&lt;p&gt;The final solution is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;positiveSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;addAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt;  &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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



&lt;p&gt;So moral of the story is.... Always look for improvements to your solutions :)  &lt;/p&gt;

&lt;h2&gt;
  
  
  Doc
&lt;/h2&gt;

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

</description>
      <category>javascript</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Netlify and Google Domains</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Mon, 01 Jun 2020 20:25:27 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/netlify-and-google-domains-hm3</link>
      <guid>https://forem.com/lost_semicolon/netlify-and-google-domains-hm3</guid>
      <description>&lt;p&gt;I have bought my own domain for a blog! I have always wanted to do and now i did! I went with google domains as it was the cheapest domain I could find. There was a good £15 difference between sites so make sure to shop around!&lt;/p&gt;

&lt;p&gt;The buying process was very simple - i just had to put in my card details and address. The set up.... should have been simpler. &lt;/p&gt;

&lt;p&gt;I have hosted my site on netlify but the process should be similar. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Netlify&lt;/strong&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In your netlify console,  go to your site and then click Domain Settings.  Click the green button "Add custom domain".&lt;br&gt;
Alternatively, there will be a "getting started" banner with option 2 being "Set up your custom domain". Click that.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will now be asked to provide the name of the domain you have bought. In my case it was "ewa.dev".&lt;br&gt;
If you own the domain the site will ask you to verify that you are the owner. Bare in mind Netlify can also provide you with a domain. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click "verify". &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Netlify will now redirect you to your domain settings where you will see your domain. You will see that your domain will have have a warning, to ask you to "check your DNS configuration".  Click to Options -&amp;gt; Set Up Netlify DNS. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is now 3 steps: &lt;br&gt;
5.1 Add domain - Netlify will ask you to re-verify your domain name &lt;br&gt;
5.2 Add DNS records  - The DNS records for your Netlify sites will be configured automatically. Unless you have email set up with your domain, you can skip this bit.&lt;br&gt;
5.3 Activate Netlify DNS - Nelify will give you names of their name savers. Keep them open and head to your domain name provider.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Google Domains&lt;/strong&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Go to your domain settings&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click DNS &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the NameServers box, select option "Use custom nameservers". For googlr domains, before I was able to add my own custom domains, I had to disable DNSSEC. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the name servers from Netlify to the google nameservers. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And Thats it! Your domain is set up - it says it can take up to 48 hours, but in my experience its pretty speedy. Ewa.dev took only 15 min to kick in. &lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quarantine Games - Pictionary!</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Wed, 08 Apr 2020 14:04:03 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/quarantine-games-pictionary-470b</link>
      <guid>https://forem.com/lost_semicolon/quarantine-games-pictionary-470b</guid>
      <description>&lt;p&gt;It is easy to feel demotivated or disconnected from your team when we are all isolating. We have started doing weekly games at work to be more connected in the team. First one is Pictionary : &lt;/p&gt;

&lt;h3&gt;
  
  
  You will need:
&lt;/h3&gt;

&lt;p&gt;*Drawing software (paint) &lt;br&gt;
*Calling + Screen Share Software (Teams, Zoom, Slack etc) &lt;/p&gt;

&lt;h3&gt;
  
  
  How it runs:
&lt;/h3&gt;

&lt;p&gt;Split into 2 &lt;a href="https://www.jamesbaum.co.uk/team-generator/"&gt;random&lt;/a&gt;  teams on the call.&lt;br&gt;
A person from each team will draw for their own team ( I think that’s the easiest). &lt;/p&gt;

&lt;p&gt;Team 1 – a person from team one uses &lt;a href="https://randomwordgenerator.com/pictionary.php"&gt;a random generator&lt;/a&gt; to pick a word. I suggest starting with "medium" difficulty. &lt;br&gt;
Person then shares their screen with paint opened ready to draw.&lt;/p&gt;

&lt;p&gt;Team 2 starts 1 min timer and GO ! &lt;br&gt;
Person from Team 1 draws the picked word&lt;br&gt;
Team 1 guesses the word.&lt;/p&gt;

&lt;p&gt;If they guess correctly, team gets a point. If not then :( &lt;br&gt;
Team 1 and Team 2 swap roles.&lt;/p&gt;

&lt;p&gt;Track your score! Do 5 rounds and see how it goes - you can do movie categories or something harder later on. Its quite hard to draw with a mouse - start small and improve over time :) &lt;/p&gt;

</description>
      <category>productivity</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>How to quit vim </title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Wed, 08 Jan 2020 16:31:20 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/how-to-quit-vim-b1l</link>
      <guid>https://forem.com/lost_semicolon/how-to-quit-vim-b1l</guid>
      <description>&lt;p&gt;Its okay, happens to all of us :D&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;press esc&lt;/li&gt;
&lt;li&gt;type :q&lt;/li&gt;
&lt;li&gt;press enter &lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Global Diversity CFP Day</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Fri, 03 Jan 2020 15:15:14 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/global-diversity-cfp-day-1ib3</link>
      <guid>https://forem.com/lost_semicolon/global-diversity-cfp-day-1ib3</guid>
      <description>&lt;p&gt;On Saturday 18th of January, at Skyscanner offices, in Glasgow, and in other 80+ locations around the world, the Global Diversity Call For Proposals(CFP) Day workshop will take place. The aim of the day is to help people from underrepresented and marginalized groups, to apply to speak at tech conferences with the goal to elevate new ideas and perspectives onto the center stage.&lt;br&gt;
The set up is simple - attendees get access to mentors and resources to allow them to identify a topic, write a proposal and map out the talk. And most importantly, the whole event is free!&lt;/p&gt;

&lt;h2&gt;
  
  
  Origins
&lt;/h2&gt;

&lt;p&gt;The idea came about in 2015 when the organiser of ScotlandJS and ScotlandCSS, Peter Aitken noticed that the number of applicants from varying backgrounds applying to speak at the conference, was incredibly low.  &lt;/p&gt;

&lt;p&gt;Peter explains: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"In 2015, 6% of CFP applicants were from underrepresented and marginalised groups. That needed to change."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At the time, the conference had anonymous voting in order to prevent speaker bias, but when the percentage of applicants is so low, the chances of being picked, are also very low. As a response to that, an idea was born to help people from underrepresented and marginalised groups to write their proposals.&lt;/p&gt;

&lt;p&gt;The result? Well it is rather remarkable. In just 3 years the number of applicants from diverse groups to ScotlandJS shot up to 35% and Global Diversity CFP Day has increased from 6 to over 80 workshops around the world.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“The key for me is that people are wanted, welcomed, and that their voice and perspectives are valued. If more people see people like themselves on stage, it will encourage them to apply also” &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why do it?
&lt;/h2&gt;

&lt;p&gt;Conferences are places where people come to learn and have interesting conversations. If the same people present similar talks, there is a limit on how much we learn and discover. In addition to the above, if the experts as viewed as coming from one particular group of people, then the decisions may not take into consideration the “invisible” section of the user base.&lt;/p&gt;

&lt;p&gt;Recently I learned a lot as I was trying to organised a note taker for the day to allow people who are hard of hearing to attend the workshop. I knew about barriers for people who were hard of hearing, or deaf but I have never considered how this impacts the day-to-day work environment. The same thing happened when my friend let me listen to her screen reader, and read code to me as she is visually impaired. Or I heard  another speaker who talked about how the block chain model is a reflection of the old system for keeping records, in villages, before record keeping was centralized.&lt;/p&gt;

&lt;p&gt;These stories are worth hearing, and I am hoping that by organizing initiatives such as the Global CFP Day, more and more people will have the opportunity to tell theirs. &lt;/p&gt;

&lt;p&gt;The Glasgow workshop will include some of the community’s very best mentors especially organisers from communities such as Agile Scotland, Ladies of Code and  CodeCraft &lt;/p&gt;

&lt;p&gt;Find a workshop near you &lt;a href="https://www.globaldiversitycfpday.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5butvpZy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1w7fs913z93g2sgljk5n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5butvpZy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1w7fs913z93g2sgljk5n.jpg" alt="CFP Day attendees photo"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>speaking</category>
      <category>conferences</category>
      <category>visibility</category>
      <category>career</category>
    </item>
    <item>
      <title>How many unique CSS properties can a div have 🤔?</title>
      <dc:creator>Lost Semicolon 💻🖱</dc:creator>
      <pubDate>Fri, 26 Jul 2019 21:12:16 +0000</pubDate>
      <link>https://forem.com/lost_semicolon/how-many-unique-css-properties-can-a-div-have-o02</link>
      <guid>https://forem.com/lost_semicolon/how-many-unique-css-properties-can-a-div-have-o02</guid>
      <description>&lt;p&gt;There are a lot of CSS properties! But just how can a div have?  Let's find out!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt;  &lt;span class="nx"&gt;totalCssProperiesNo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="nx"&gt;totalCssProperiesNo&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;totalCssProperiesNo&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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



&lt;p&gt;You get 522! As of today.&lt;/p&gt;

&lt;p&gt;Thanks to JavaScript teacher for his CSS Dictionary book where he ran his code last year and got 415.&lt;/p&gt;

</description>
      <category>css</category>
      <category>codenewbie</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
