<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>miku86</title>
    <link href="https://miku86.com/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://miku86.com"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2024-01-18T00:00:00+00:00</updated>
    <id>https://miku86.com/atom.xml</id>
    <entry xml:lang="en">
        <title>Simple bookmarks</title>
        <published>2024-01-18T00:00:00+00:00</published>
        <updated>2024-01-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2024-01-18/" type="text/html"/>
        <id>https://miku86.com/2024-01-18/</id>
        
        <content type="html">&lt;p&gt;As I stated in many posts, I like simple tools.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m a person of few browser tabs and few bookmarks, but I still love to simplify my life.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I implemented a simple bookmarking feature on my computer, copied from Luke Smith:
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;odysee.com&#x2F;@Luke:7&#x2F;bookmarking-for-unix-chads-(for:0&quot;&gt;simple bookmarks&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So in the end my workflow is like that:&lt;&#x2F;p&gt;
&lt;p&gt;Saving bookmark:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Press Ctrl+L to highlight URL bar&lt;&#x2F;li&gt;
&lt;li&gt;Press Ctrl+C to copy URL&lt;&#x2F;li&gt;
&lt;li&gt;Press Alt+Delete to save URL in my bookmarks file&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Pasting bookmark:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Press Ctrl+L to highlight URL bar&lt;&#x2F;li&gt;
&lt;li&gt;Press Ctrl+Insert to show my bookmarks file in my linux launcher (dmenu)&lt;&#x2F;li&gt;
&lt;li&gt;Search the right bookmark and hit Enter&lt;&#x2F;li&gt;
&lt;li&gt;Hit Enter again to submit pasted URL in URL bar&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Why that?&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;simple solution&lt;&#x2F;li&gt;
&lt;li&gt;no distracting bookmarks in my browser&lt;&#x2F;li&gt;
&lt;li&gt;browser-agnostic&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Renaissance man</title>
        <published>2024-01-11T00:00:00+00:00</published>
        <updated>2024-01-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2024-01-11/" type="text/html"/>
        <id>https://miku86.com/2024-01-11/</id>
        
        <content type="html">&lt;p&gt;I love the idea of the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Renaissance_man&quot;&gt;Renaissance man&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;After re-reading some great books (e.g. &amp;quot;Radical Simplicity&amp;quot;, &amp;quot;Early Retirement Extreme&amp;quot;, &amp;quot;Your Money or Your Life&amp;quot;), I
invested more and more time in the last few months to re-evaluate some of my thoughts about money in general, skills,
trading etc.&lt;&#x2F;p&gt;
&lt;p&gt;Most of my thoughts revolved around my general real-life skills, especially compared to my very handy co-workers, 
my real-life skills are very rare. I can put a nail into the wall, but that&#x27;s mostly it.&lt;&#x2F;p&gt;
&lt;p&gt;Where did my attitude come from? Mostly from the idea that it&#x27;s more efficient to trade my money for another person&#x27;s
services instead of learning and doing it myself.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I decided to learn more real-life skills.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve already started by:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;cooking bread spread&lt;&#x2F;li&gt;
&lt;li&gt;replacing the battery of my watch&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;What are your real-life skills?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Clean Craftsmanship</title>
        <published>2023-12-15T00:00:00+00:00</published>
        <updated>2023-12-15T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-12-15/" type="text/html"/>
        <id>https://miku86.com/2023-12-15/</id>
        
        <content type="html">&lt;p&gt;I finally made it through Clean Craftsmanship by Uncle Bob.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve read all his other books, so I&#x27;m coming to the conclusion, that Clean Craftsmanship
is the best fitting book for an individual software engineer.&lt;&#x2F;p&gt;
&lt;p&gt;For beginners, it includes the most important parts of Clean Code in the Refactoring chapter, 
while overall focusing on the more important strategic parts.&lt;&#x2F;p&gt;
&lt;p&gt;Great book about the fundamentals, can recommend!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Playing with local AI</title>
        <published>2023-12-04T00:00:00+00:00</published>
        <updated>2023-12-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-12-04/" type="text/html"/>
        <id>https://miku86.com/2023-12-04/</id>
        
        <content type="html">&lt;p&gt;Now with local, privacy-respecting AI available, I started playing around with it.&lt;&#x2F;p&gt;
&lt;p&gt;What I did:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Installed &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;jmorganca&#x2F;ollama&quot;&gt;ollama&lt;&#x2F;a&gt; with Docker (probably the easiest way, should work on all platforms)&lt;&#x2F;li&gt;
&lt;li&gt;Searched for and installed some basic models (the &amp;quot;AI&amp;quot;).&lt;&#x2F;li&gt;
&lt;li&gt;Customized a prompt to make the AI behave like in an specific environment (&amp;quot;as a grandma&amp;quot;, &amp;quot;as a engineer&amp;quot;, &amp;quot;as a copywriter&amp;quot;).&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;I&#x27;m currently running &lt;code&gt;Openchat 3.5 7b&lt;&#x2F;code&gt;. It needs 5GB of disc storage and mostly around 2GB RAM on
my device.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;The pros so far:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;no connection to the outside world (= privacy-respecting)&lt;&#x2F;li&gt;
&lt;li&gt;no SEO bullshit in contrast when using a search engine&lt;&#x2F;li&gt;
&lt;li&gt;I can use natural language instead of optimized search terms&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The cons so far:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;slower than using a search engine&lt;&#x2F;li&gt;
&lt;li&gt;older training data (AFAIR 2023 march)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Apps I use</title>
        <published>2023-11-08T00:00:00+00:00</published>
        <updated>2023-11-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-11-08/" type="text/html"/>
        <id>https://miku86.com/2023-11-08/</id>
        
        <content type="html">&lt;p&gt;Although I have a dedicated page for the stuff I use, I reply to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;kevquirk.com&#x2F;my-default-apps-at-the-end-of-2023&quot;&gt;kevquirk&#x27;s post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;to-do: pen and paper&lt;&#x2F;li&gt;
&lt;li&gt;calendar: pen and paper&lt;&#x2F;li&gt;
&lt;li&gt;reading: pen and paper&lt;&#x2F;li&gt;
&lt;li&gt;shopping lists: pen and paper&lt;&#x2F;li&gt;
&lt;li&gt;notes: vim with markdown files&lt;&#x2F;li&gt;
&lt;li&gt;contacts: vim with vcf files&lt;&#x2F;li&gt;
&lt;li&gt;word processing: vim with markdown files&lt;&#x2F;li&gt;
&lt;li&gt;spreadsheets: gnumeric&lt;&#x2F;li&gt;
&lt;li&gt;personal finance: gnumeric&lt;&#x2F;li&gt;
&lt;li&gt;presentations: vscodium (one file per slide)&lt;&#x2F;li&gt;
&lt;li&gt;code editor: vim&#x2F;vscodium&lt;&#x2F;li&gt;
&lt;li&gt;mail service: own domain with all-inkl.com&lt;&#x2F;li&gt;
&lt;li&gt;mail client: neomutt (terminal)&lt;&#x2F;li&gt;
&lt;li&gt;cloud storage: -&lt;&#x2F;li&gt;
&lt;li&gt;rss service: -&lt;&#x2F;li&gt;
&lt;li&gt;rss client: newsboat (terminal)&lt;&#x2F;li&gt;
&lt;li&gt;launcher: dmenu&lt;&#x2F;li&gt;
&lt;li&gt;photo library: external hard drive&lt;&#x2F;li&gt;
&lt;li&gt;web browser: librewolf&lt;&#x2F;li&gt;
&lt;li&gt;bookmarks: librewolf&lt;&#x2F;li&gt;
&lt;li&gt;chat: signal, whatsapp&lt;&#x2F;li&gt;
&lt;li&gt;music: yt-dlp + mpv&lt;&#x2F;li&gt;
&lt;li&gt;podcasts: yt-dlp + mpv&lt;&#x2F;li&gt;
&lt;li&gt;password management: keepassxc&lt;&#x2F;li&gt;
&lt;li&gt;social media: mastodon (rarely)&lt;&#x2F;li&gt;
&lt;li&gt;weather: &lt;code&gt;curl https:&#x2F;&#x2F;v2.wttr.in&#x2F;[city]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;search: duckduckgo lite &#x2F; searx-ng&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Bloat</title>
        <published>2023-10-05T00:00:00+00:00</published>
        <updated>2023-10-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-10-05/" type="text/html"/>
        <id>https://miku86.com/2023-10-05/</id>
        
        <content type="html">&lt;p&gt;I just recently setup our tablet device from scratch.&lt;&#x2F;p&gt;
&lt;p&gt;One thing that repeatedly came to the surface: software bloat.&lt;&#x2F;p&gt;
&lt;p&gt;After a factory reset, I deleted dozens of useless Android packages via
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;0x192&#x2F;universal-android-debloater&quot;&gt;Universal Android Debloater&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Even the default applications are bloat, e.g. the Huawei file manager requires 137 megabytes of storage,
but &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;martinmimigames&#x2F;little-file-explorer&quot;&gt;Little File Explorer&lt;&#x2F;a&gt; just requires 137 KILObytes.&lt;&#x2F;p&gt;
&lt;p&gt;This is 1000 times more storage space...&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Different</title>
        <published>2023-07-28T00:00:00+00:00</published>
        <updated>2023-07-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-07-28/" type="text/html"/>
        <id>https://miku86.com/2023-07-28/</id>
        
        <content type="html">&lt;p&gt;Things I do differently:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;I prefer simple things: dinner: bread, quark, veggies; commuting: bicycle; todos: pen and paper; 
clock: Casio wristwatch etc.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;I mostly work laying down: I lay down, laptop on my lap. After 30-45 minutes I stand up and move.
No neck, eye, back, shoulder pain, because I move all the time.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;I use a 12.5 inch laptop from 2012: I use a tiling windows manager in tabbed mode, so any window
is fullscreen. No need to move, sort or search for windows. The device is old, so I use simple
tools that don&#x27;t need that much performance (&lt;a href=&quot;&#x2F;uses&#x2F;&quot;&gt;linux, vim, mutt, lf etc.&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;I workout a little bit every day: I sleep, eat, workout every day, because this is the simplest 
schedule to stay healthy. No dedicated &amp;quot;workout&amp;quot; days that need scheduling or skipping.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;I make things harder: Staying mentally healthy and robust needs hardship from time to time. This
is why I sometimes make things harder, e.g. taking a detour with my bike or fasting for 36 hours.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;I mostly use the default config: Being able to work on different devices (laptop, cloud server
etc.) is way easier if I don&#x27;t have to setup the devices for x hours. If I need some special
config, I keep it as small as possible.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Human</title>
        <published>2023-05-20T00:00:00+00:00</published>
        <updated>2023-05-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-05-20/" type="text/html"/>
        <id>https://miku86.com/2023-05-20/</id>
        
        <content type="html">&lt;p&gt;I am a human.&lt;&#x2F;p&gt;
&lt;p&gt;You are a human.&lt;&#x2F;p&gt;
&lt;p&gt;The person, who cleans the street, is a human.&lt;&#x2F;p&gt;
&lt;p&gt;The person, who sells me a coffee, is a human.&lt;&#x2F;p&gt;
&lt;p&gt;The person, who cuts my line, is a human.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Quick bucks</title>
        <published>2023-05-12T00:00:00+00:00</published>
        <updated>2023-05-12T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-05-12/" type="text/html"/>
        <id>https://miku86.com/2023-05-12/</id>
        
        <content type="html">&lt;p&gt;Nowadays everyone is talking about AI.&lt;&#x2F;p&gt;
&lt;p&gt;Twitter, Linkedin etc. is full of professional AI folks, who want me to sell their shit.&lt;&#x2F;p&gt;
&lt;p&gt;Making some quick bucks by selling some hot, but not-so-much-proven takes, seems to be very unsustainable business.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Not-so-perfect equipment</title>
        <published>2023-05-11T00:00:00+00:00</published>
        <updated>2023-05-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-05-11/" type="text/html"/>
        <id>https://miku86.com/2023-05-11/</id>
        
        <content type="html">&lt;p&gt;Back when I coached some soccer kids, I had this heuristic:&lt;&#x2F;p&gt;
&lt;p&gt;The kid with the best equipment was mostly not the best player, mostly not even in the upper third.
But these 12-15 year olds talked so much about their equipment.&lt;&#x2F;p&gt;
&lt;p&gt;I think about this heuristic a lot.&lt;&#x2F;p&gt;
&lt;p&gt;My wardrobe only contains one same outfit for every sport I do. (strength training, biking, soccer,
volleyball)&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Why?&lt;&#x2F;strong&gt; &lt;&#x2F;p&gt;
&lt;p&gt;I don&#x27;t want to get distracted by thoughts about not-so-important stuff.&lt;&#x2F;p&gt;
&lt;p&gt;Because being proficient in a sport is all about training the basics, 
first going for the high-impact, low-hanging fruits:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;strength training: more compound exercises, higher frequency&lt;&#x2F;li&gt;
&lt;li&gt;biking: lower weight&lt;&#x2F;li&gt;
&lt;li&gt;soccer: lower weight, better passing skills, better communication skills &lt;&#x2F;li&gt;
&lt;li&gt;volleyball: lower weight, better passing skills, better anticipation&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Arte</title>
        <published>2023-05-02T00:00:00+00:00</published>
        <updated>2023-05-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-05-02/" type="text/html"/>
        <id>https://miku86.com/2023-05-02/</id>
        
        <content type="html">&lt;p&gt;I don&#x27;t watch that much stuff, but when I watch something,
it&#x27;s Arte, a French&#x2F;German TV station:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Arte&quot;&gt;Wikipedia&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;invidious.tiekoetter.com&#x2F;channel&#x2F;UCLLibJTCy3sXjHLVaDimnpQ&quot;&gt;Invidious&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Spring</title>
        <published>2023-02-23T00:00:00+00:00</published>
        <updated>2023-02-23T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-02-23/" type="text/html"/>
        <id>https://miku86.com/2023-02-23/</id>
        
        <content type="html">&lt;p&gt;After all the dark days full of sleep, spring is awakening.&lt;&#x2F;p&gt;
&lt;p&gt;Chirping birds in the morning - messengers of a new day.&lt;&#x2F;p&gt;
&lt;p&gt;Nature shows itself in a new guise - things have gone, new ones are coming.&lt;&#x2F;p&gt;
&lt;p&gt;The sounds of nature soothe me and awaken me.&lt;&#x2F;p&gt;
&lt;p&gt;I love spring.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Every evening</title>
        <published>2023-01-27T00:00:00+00:00</published>
        <updated>2023-01-27T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-01-27/" type="text/html"/>
        <id>https://miku86.com/2023-01-27/</id>
        
        <content type="html">&lt;p&gt;I&#x27;m currently a lot into conceptual thinking.&lt;&#x2F;p&gt;
&lt;p&gt;One concept I really love is automation.&lt;&#x2F;p&gt;
&lt;p&gt;Automation frees energy for more valuable stuff.
Automation removes the probability of errors.
Automation leads to faster iteration cycles.&lt;&#x2F;p&gt;
&lt;p&gt;This doesn&#x27;t have to be technically.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Every evening, I make some oatmeal for me and my girlfriend. Boiling water, mixing the ingredients.&lt;&#x2F;p&gt;
&lt;p&gt;Every morning, I pack it into a bag.&lt;&#x2F;p&gt;
&lt;p&gt;Every day, we have a healthy, simple, automated meal.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Automated isn&#x27;t &amp;quot;I don&#x27;t have to do anything anymore.&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s more about the energy.&lt;&#x2F;p&gt;
&lt;p&gt;Same recipe, same ingredients, same workflow, same output.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Up and down</title>
        <published>2023-01-26T00:00:00+00:00</published>
        <updated>2023-01-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2023-01-26/" type="text/html"/>
        <id>https://miku86.com/2023-01-26/</id>
        
        <content type="html">&lt;p&gt;My last post is 5 months old.&lt;&#x2F;p&gt;
&lt;p&gt;Most of the time I started writing, then it blew up and was totally incomprehensible,
so I postponed publishing it (to never).&lt;&#x2F;p&gt;
&lt;p&gt;I didn&#x27;t stop writing, I actually wrote so much stuff.&lt;&#x2F;p&gt;
&lt;p&gt;But now it feels wrong to publish yesterday&#x27;s thoughts.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Cost per month</title>
        <published>2022-08-29T00:00:00+00:00</published>
        <updated>2022-08-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-08-29/" type="text/html"/>
        <id>https://miku86.com/2022-08-29/</id>
        
        <content type="html">&lt;p&gt;We own stuff.&lt;&#x2F;p&gt;
&lt;p&gt;We work so that we can own stuff.&lt;&#x2F;p&gt;
&lt;p&gt;But how much does this stuff cost?&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s say I buy a smartphone for 300€.&lt;&#x2F;p&gt;
&lt;p&gt;Is this cheaper than another one for 900€?&lt;&#x2F;p&gt;
&lt;p&gt;If everything else is equal: yes.&lt;&#x2F;p&gt;
&lt;p&gt;But is everything else equal? Probably not.&lt;&#x2F;p&gt;
&lt;p&gt;Maybe one phone breaks less often. Or the battery dies faster. Or the software doesn&#x27;t get any updates.&lt;&#x2F;p&gt;
&lt;p&gt;So I think saying stuff like &amp;quot;A phone for 300€ is cheaper than a 900€ phone.&amp;quot; is pretty useless,
because this only includes the one-time cashflow of buying it.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s also way harder to compare the phone to another device, e.g. a laptop, or even your housing cost.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;idea&quot;&gt;Idea&lt;&#x2F;h2&gt;
&lt;p&gt;Instead of thinking in &amp;quot;cost of buying&amp;quot;, I use &amp;quot;cost per month&amp;quot;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;examples&quot;&gt;Examples&lt;&#x2F;h3&gt;
&lt;p&gt;Motorola smartphone: I bought it in 2015-02 for 120€. It lasted for 90 months so far.
=&amp;gt; 120€ &#x2F; 90 = 1.3€&#x2F;month&lt;&#x2F;p&gt;
&lt;p&gt;Thinkpad X230: I bought it in 2022-02 for 120€. It lasted for 6 months so far.
=&amp;gt; 120€ &#x2F; 6 = 20€&#x2F;month&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s interesting to see that if I&#x27;ll use my Thinkpad just for some additional 6 months,
the cost per month will half down to 10€&#x2F;month.&lt;&#x2F;p&gt;
&lt;p&gt;Just for comparison: If you buy a new phone every 3 years for 240€, you pay 6.6€&#x2F;month.
If you buy a new phone every 5 years for 600€, you pay 10€&#x2F;month.&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Moto E 2015&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Normal Phone&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Sustainable Phone&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Thinkpad X230&lt;&#x2F;th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Housing&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Cost (€)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;120&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;240&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;600&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;120&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;-&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Used (Months)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;90&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;36&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;60&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;6&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;-&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Cost per Month (€)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1.3&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;6.6&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;10.0&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;20.0&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;600&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Work per Month&lt;br&gt; (Hours, 20€&#x2F;h net)&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;0.1&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;0.3&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;0.5&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;1.0&lt;&#x2F;td&gt;&lt;td style=&quot;text-align: right&quot;&gt;30.0&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;br&gt;
&lt;p&gt;These numbers seem to be low.&lt;&#x2F;p&gt;
&lt;p&gt;Especially in contrast to paying 600€ per month for housing.&lt;&#x2F;p&gt;
&lt;p&gt;Buying a sustainable phone, that lasts longer, should be affordable for many people.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>About the news</title>
        <published>2022-08-05T00:00:00+00:00</published>
        <updated>2022-08-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-08-05/" type="text/html"/>
        <id>https://miku86.com/2022-08-05/</id>
        
        <content type="html">&lt;p&gt;Most of us read the news.&lt;&#x2F;p&gt;
&lt;p&gt;Some people even have news apps on their smartphones to stay up-to-date.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s talk about the news.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Visiting one big German news site (spiegel.de), two huge ads are welcoming me, eating around 30% of the whole screen.&lt;&#x2F;p&gt;
&lt;p&gt;Scrolling down, one of them stays on the right side of the screen, forever.&lt;&#x2F;p&gt;
&lt;p&gt;Why do I tell you this?&lt;&#x2F;p&gt;
&lt;p&gt;Because the news site makes money out of this.&lt;&#x2F;p&gt;
&lt;p&gt;No big news, and the people working there want to feed their kids, alright.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;But let&#x27;s look at their incentives.&lt;&#x2F;p&gt;
&lt;p&gt;The news site (spiegel.de) is owned by a for-profit company (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;de.wikipedia.org&#x2F;wiki&#x2F;Spiegel-Verlag_Rudolf_Augstein_GmbH_%26_Co._KG&quot;&gt;Wikipedia (German)&lt;&#x2F;a&gt;) and ~19% of the revenue comes from online ads (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;de.wikipedia.org&#x2F;wiki&#x2F;Spiegel-Verlag_Rudolf_Augstein_GmbH_%26_Co._KG#Finanzzahlen&quot;&gt;Wikipedia (German)&lt;&#x2F;a&gt;), year-over-year growing.&lt;&#x2F;p&gt;
&lt;p&gt;How this works:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Advertiser gives money to the news site for each click or each sell.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;News site places money-making ads more prominent than other ads.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;So what (scammy) ads do we see the most? Health and finances, because people buy most stuff in these categories.&lt;&#x2F;p&gt;
&lt;p&gt;And because it&#x27;s not about the usefulness of the stuff, but only about making money, 
there are few morale incentives to only advertise useful stuff.&lt;&#x2F;p&gt;
&lt;p&gt;This is why we see ads like &amp;quot;Angela Merkel buys these crypto coins!!!&amp;quot;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;&lt;strong&gt;Question&lt;&#x2F;strong&gt;: Short-term: Which scenario has the higher probability to make people buy the advertised stuff?&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;A user visits once per week to read a long-form essay and who is focused on the content?&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;A user visits ten times per day to jump from short-form news to short-form news to feel &amp;quot;informed&amp;quot;?&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;&lt;strong&gt;Question&lt;&#x2F;strong&gt;: Long-term: Which user is more hooked into coming back to the news site to mindlessly scroll through the site and maybe click on an ad to buy some stuff?&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Advanced Questions&lt;&#x2F;strong&gt;: &lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Why do &lt;em&gt;you&lt;&#x2F;em&gt; read the news?&lt;&#x2F;li&gt;
&lt;li&gt;Do you gain &lt;em&gt;useful&lt;&#x2F;em&gt; knowledge by reading long-form content or short-form content? &lt;&#x2F;li&gt;
&lt;li&gt;Is any of the current news still relevant next week? &lt;&#x2F;li&gt;
&lt;li&gt;Is there some actionable advice in news?&lt;&#x2F;li&gt;
&lt;li&gt;Are you trapped in the idea that &amp;quot;I read news, because I learn something from it, so I feel very productive.&amp;quot;? (trap: any information seems to be somehow useful)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Some interesting questions and I think having a look at the tactics the biggest social media advertising companies (Facebook, Twitter etc.) use, lead us the way.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;My simple solution: I don&#x27;t read so-called &amp;quot;news&amp;quot;. &lt;strong&gt;If I want to stay up-to-date, I go to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Portal:Current_events&quot;&gt;Current Events on Wikipedia&lt;&#x2F;a&gt;&lt;&#x2F;strong&gt;, mostly once per week to get a broad overview. &lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m also just on click away to learn more about the related topics.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>On notifications</title>
        <published>2022-08-01T00:00:00+00:00</published>
        <updated>2022-08-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-08-01/" type="text/html"/>
        <id>https://miku86.com/2022-08-01/</id>
        
        <content type="html">&lt;p&gt;So when you are interested in something, you want to stay up-to-date.&lt;&#x2F;p&gt;
&lt;p&gt;This is why we once invented notifications.&lt;&#x2F;p&gt;
&lt;p&gt;&amp;quot;Hey, if you are interested, enable the notification and get the updates.&amp;quot;&lt;&#x2F;p&gt;
&lt;p&gt;Awesome, now I don&#x27;t have to manually care about it anymore.&lt;&#x2F;p&gt;
&lt;p&gt;But things changed.&lt;&#x2F;p&gt;
&lt;p&gt;Adding business and money to the interwebs, we now have this landscape of user-hostile attention-hijacking notifications crap.&lt;&#x2F;p&gt;
&lt;p&gt;Nearly every smartphone application uses this concept.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;ve become &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Classical_conditioning&quot;&gt;Pavlov&#x27;s dog&lt;&#x2F;a&gt;. (See &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;media&#x2F;wikipedia&#x2F;commons&#x2F;thumb&#x2F;d&#x2F;d7&#x2F;Pavlov%27s_dog.svg&#x2F;640px-Pavlov%27s_dog.svg.png&quot;&gt;the mechanism in action&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;I see this everywhere: The smartphone sends a notification sound &lt;em&gt;brng&lt;&#x2F;em&gt; , and the dog (&#x2F;&amp;quot;well educated human being&amp;quot;) takes out their smartphone to check the latest &amp;quot;important&amp;quot; update.&lt;&#x2F;p&gt;
&lt;p&gt;And this goes on and on every 30 seconds.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;My simple solution: &lt;strong&gt;I disabled all notifications years ago.&lt;&#x2F;strong&gt; If I want to stay up-to-date, I intentionally visit the desired webpage or application.&lt;&#x2F;p&gt;
&lt;p&gt;If I do not visit it, I probably have some more interesting stuff to do.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>The Case Against Social Media</title>
        <published>2022-07-26T00:00:00+00:00</published>
        <updated>2022-07-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-07-26/" type="text/html"/>
        <id>https://miku86.com/2022-07-26/</id>
        
        <content type="html">&lt;p&gt;I just watched this interesting episode of the Lex Fridman Podcast with the social scientist Jonathan Haidt: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;invidious.snopyta.org&#x2F;watch?v=f0un-l1L8Zw&quot;&gt;The Case Against Social Media&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;When I talk about social media usage, I always argue for prohibiting it for kids until they are adults.&lt;&#x2F;p&gt;
&lt;p&gt;People go like &amp;quot;You can&#x27;t do this, because they will become social outcasts.&amp;quot; or &amp;quot;All other kids do this too.&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;Jonathan Haidt has some interesting ideas about the topic and how to tackle it.&lt;&#x2F;p&gt;
&lt;p&gt;He also created a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.google.com&#x2F;document&#x2F;d&#x2F;1vVAtMCQnz8WVxtSNQev_e1cGmY9rnY96ecYuAj6C548&#x2F;&quot;&gt;roundup of scientific papers&lt;&#x2F;a&gt; about the topic.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Quotes:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The main one, I think: [...] it&#x27;s living a life where you&#x27;re thinking all the time about posting. You&#x27;re scrolling through and everyones life is looking better than yours, because it&#x27;s fake. [...] Once you start posting, that takes over your mind [...] and even if you are &amp;quot;only&amp;quot; spending 5 or 6 hours a day on Instagram, you&#x27;re always thinking about it. &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;And when you&#x27;re in class you&#x27;re thinking about &amp;quot;How are people responding about the post that I made?&amp;quot;. I mean I do it [...] and I can&#x27;t help it like I check 20 times per day - this is terrible. Imagine a 12 year old girl. [...]. I see some young women, women in their 20s and 30s putting up sexy photos of themselves and this is so sad. &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>No wiki, less complexity, more doing</title>
        <published>2022-07-19T00:00:00+00:00</published>
        <updated>2022-07-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-07-19/" type="text/html"/>
        <id>https://miku86.com/2022-07-19/</id>
        
        <content type="html">&lt;p&gt;I love the wiki of &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;supermemo.guru&#x2F;wiki&#x2F;&quot;&gt;Piotr Wozniak&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Because I like wikis and publishing my knowledge, I did a lot of research about all the wiki softwares out there.&lt;&#x2F;p&gt;
&lt;p&gt;There is actually a cool site to search for different features of wikis: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.wikimatrix.org&#x2F;wizard&quot;&gt;WikiMatrix&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I installed some of them: Wiki.js, MediaWiki and TiddlyWiki.&lt;&#x2F;p&gt;
&lt;p&gt;Then I did nothing for weeks.&lt;&#x2F;p&gt;
&lt;p&gt;The thing is, I already have a great tool to publish my knowledge: this blog.&lt;&#x2F;p&gt;
&lt;p&gt;So instead of starting a new project (again), I won&#x27;t do it.
Less complexity, less maintenance, less excuses.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>What I currently do</title>
        <published>2022-07-14T00:00:00+00:00</published>
        <updated>2022-07-14T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-07-14/" type="text/html"/>
        <id>https://miku86.com/2022-07-14/</id>
        
        <content type="html">&lt;p&gt;Been away from the blog for some weeks.&lt;&#x2F;p&gt;
&lt;p&gt;What I currently do:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hitting the gym everyday&lt;&#x2F;strong&gt;: I love simplicity, that&#x27;s why I hit the gym &lt;em&gt;every day&lt;&#x2F;em&gt;. Press, row, deadlift. No need to think about if today is a gym day, which exercises to do and so on.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Eating more&lt;&#x2F;strong&gt;: I try to have a light caloric plus of ~200 kilocalories daily. It&#x27;s awesome, feeling strong. And yes, my fundamental meals are the same &lt;em&gt;every day&lt;&#x2F;em&gt;. Some variations only for dinner.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Riding my bike&lt;&#x2F;strong&gt;: Just to have some constant psychological workout.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;Testing new web programming tools&lt;&#x2F;strong&gt;: I have a strong background in React. In the last year I&#x27;ve become very frustrated with all the complexity and disadvantages of it. That&#x27;s why I came back so server stuff like NestJS and simple templating. I also had a look at newer tools, my favorites so far are &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.solidjs.com&#x2F;&quot;&gt;SolidJS&lt;&#x2F;a&gt; and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fresh.deno.dev&#x2F;&quot;&gt;Fresh&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>4000 weeks</title>
        <published>2022-05-29T00:00:00+00:00</published>
        <updated>2022-05-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-05-29/" type="text/html"/>
        <id>https://miku86.com/2022-05-29/</id>
        
        <content type="html">&lt;p&gt;Although I don&#x27;t read that many books nowadays, because a lot of them feel like procrastination, 
I can recommend one:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;4000 weeks by Oliver Burkeman&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I love hardship, but it&#x27;s hard for me to talk about it, because I have the feeling that everyone around me loves convenience and comfort.&lt;&#x2F;p&gt;
&lt;p&gt;I see some virtue in doing uncomfortable stuff, e.g. waking up at 5am, fasting for 36 hours, working out, climbing hills with my bike.&lt;&#x2F;p&gt;
&lt;p&gt;The author talks a lot about the virtue of doing hard stuff and how to &amp;quot;manage your time&amp;quot;, but without some busy-ness tactics.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Some lovely quotes:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;What “matters” is subjective, so you’ve no grounds for assuming that there will be time for everything that you, or your employer, or your culture happens to deem important. But the other exasperating issue is that if you succeed in fitting more in, you’ll find the goalposts start to shift: more things will begin to seem important, meaningful, or obligatory. Acquire a reputation for doing your work at amazing speed, and you’ll be given more of it. Figure out how to spend enough time with your kids and at the office, so you don’t feel guilty about either, and you’ll suddenly feel some new social pressure: to spend more time exercising or to join the parent-teacher association. The same goes for chores: when housewives first got access to “labor-saving” devices like washing machines and vacuum cleaners, no time was saved at all, because society’s standards of cleanliness simply rose to offset the benefits; now that you could return each of your husband’s shirts to a spotless condition after a single wearing, it began to feel like you should, to show how much you loved him. “Work expands so as to fill the time available for its completion.&amp;quot;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;The general principle in operation is one you might call the “efficiency trap.” Rendering yourself more efficient — either by implementing various productivity techniques or by driving yourself harder — won’t generally result in the feeling of having “enough time,” because, all else being equal, the demands will increase to offset any benefits. Far from getting things done, you’ll be creating new things to do.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;... it isn’t really the thought that counts, but the effort — which is to say, the inconvenience. When you render the process more convenient, you drain it of its meaning.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;About apps and other technologies, that make our lives easier:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;It’s true that everything runs more smoothly this way. But smoothness, it turns out, is a dubious virtue, since it’s often the unsmoothed textures of life that make it livable, helping nurture the relationships that are crucial for mental and physical health, and for the resilience of our communities. &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Learning databases</title>
        <published>2022-05-17T00:00:00+00:00</published>
        <updated>2022-05-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-05-17/" type="text/html"/>
        <id>https://miku86.com/2022-05-17/</id>
        
        <content type="html">&lt;p&gt;Over the last few weeks I stepped up my (relational) database game.&lt;&#x2F;p&gt;
&lt;p&gt;Did some video courses on coursera, read some books.&lt;&#x2F;p&gt;
&lt;p&gt;My recommendations:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.csulb.edu&#x2F;colleges&#x2F;coe&#x2F;cecs&#x2F;dbdesign&#x2F;dbdesign.php&quot;&gt;Database design with UML and SQL&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;pragprog.com&#x2F;titles&#x2F;bksqla&#x2F;sql-antipatterns&#x2F;&quot;&gt;SQL Antipatterns&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Why? Because just typing some SQL statement doesn&#x27;t tell you anything about why you should type this.&lt;&#x2F;p&gt;
&lt;p&gt;Both books explain a lot of fundamentals, solved problems and feedback included.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Don&#x27;t ever work for someone you don&#x27;t want to become.</title>
        <published>2022-05-04T00:00:00+00:00</published>
        <updated>2022-05-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-05-04/" type="text/html"/>
        <id>https://miku86.com/2022-05-04/</id>
        
        <content type="html">&lt;p&gt;I love this one.&lt;&#x2F;p&gt;
&lt;p&gt;If you spend 40 hours per week at your job (40% of your waking hours), 
you will partially become like your co-workers, managers and bosses.&lt;&#x2F;p&gt;
&lt;p&gt;Choose wisely who you work for.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Smartphones become mandatory</title>
        <published>2022-03-26T00:00:00+00:00</published>
        <updated>2022-03-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-03-26/" type="text/html"/>
        <id>https://miku86.com/2022-03-26/</id>
        
        <content type="html">&lt;p&gt;Got this letter from my bank: some products will get merged, I&#x27;ll get a new card and so on.&lt;&#x2F;p&gt;
&lt;p&gt;Reading through the terms of service, I just found out that it would stop me using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Transaction_authentication_number#ChipTAN_&#x2F;_Sm@rt-TAN_&#x2F;_CardTAN&quot;&gt;ChipTAN&lt;&#x2F;a&gt; and I would have to use their smartphone app.&lt;&#x2F;p&gt;
&lt;p&gt;I see this more and more: smartphone apps become mandatory.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Dokku love</title>
        <published>2022-02-28T00:00:00+00:00</published>
        <updated>2022-02-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-02-28/" type="text/html"/>
        <id>https://miku86.com/2022-02-28/</id>
        
        <content type="html">&lt;p&gt;I started using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dokku.com&#x2F;&quot;&gt;dokku&lt;&#x2F;a&gt; back in 2020, but because I didn&#x27;t have that much knowledge about the concepts, I somehow quit using it.&lt;&#x2F;p&gt;
&lt;p&gt;The last few months I became very unhappy with the tools I used - heroku and render.&lt;&#x2F;p&gt;
&lt;p&gt;On heroku, I got 550 free hours without credit card, this means 23 full days for all my projects together.
Furthermore heroku doesn&#x27;t seem to offer file storage to use sqlite (I have no need to use postgresql).&lt;&#x2F;p&gt;
&lt;p&gt;Render has file storage, but only with a paid plan for each project.&lt;&#x2F;p&gt;
&lt;p&gt;I know that developers (and investors) want to make money, this is just not a good fit between us.&lt;&#x2F;p&gt;
&lt;p&gt;I run 5 very small projects, so I started to take a look at dokku again - and so far I love it.
I am 2 years wiser now, so I think I&#x27;ll be able to solve my problems faster.&lt;&#x2F;p&gt;
&lt;p&gt;Actually, I managed to setup 3 of my 5 apps, two in TypeScript, one in Django.
Wrote a script to do an automated setup.&lt;&#x2F;p&gt;
&lt;p&gt;No problems so far.&lt;&#x2F;p&gt;
&lt;p&gt;Thanks for this awesome tool.&lt;&#x2F;p&gt;
&lt;p&gt;PS: dokku is FOSS, heroku and render are not, so I own my tools.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>People suffer and die</title>
        <published>2022-02-26T00:00:00+00:00</published>
        <updated>2022-02-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-02-26/" type="text/html"/>
        <id>https://miku86.com/2022-02-26/</id>
        
        <content type="html">&lt;p&gt;Since this invasion started, I read a lot of news about it.&lt;&#x2F;p&gt;
&lt;p&gt;But why? I can&#x27;t help. I don&#x27;t know much about it.&lt;&#x2F;p&gt;
&lt;p&gt;Although I had &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;International_relations&quot;&gt;International relations&lt;&#x2F;a&gt; as my major at university, 
I don&#x27;t know much about the current conflict.&lt;&#x2F;p&gt;
&lt;p&gt;I just know one thing: people suffer and die.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>The boring stuff</title>
        <published>2022-02-16T00:00:00+00:00</published>
        <updated>2022-02-16T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-02-16/" type="text/html"/>
        <id>https://miku86.com/2022-02-16/</id>
        
        <content type="html">&lt;p&gt;I love the boring stuff.&lt;&#x2F;p&gt;
&lt;p&gt;Some years ago I was heavy into tech. &lt;&#x2F;p&gt;
&lt;p&gt;Actually, I held some overclocking world records with the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;List_of_AMD_Athlon_XP_microprocessors#Desktop_CPU&quot;&gt;AMD Athlon XP&lt;&#x2F;a&gt; back in ~2001-2002.&lt;&#x2F;p&gt;
&lt;p&gt;I owned the newest gear, used the newest tools. Shiny stuff all over the place.&lt;&#x2F;p&gt;
&lt;p&gt;But using shiny things has some big disadvantages, mostly because stuff breaks all the time and help and knowledge are hard to find.&lt;&#x2F;p&gt;
&lt;p&gt;And I dislike the mindset of learned helplessness.&lt;&#x2F;p&gt;
&lt;p&gt;Advertising has taught us these ideas:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;quot;If I would have this cool car, I would have more friends.&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;If I would have a sixpack, I would have a great relationship.&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;If I would have this new macbook, I would be a better software engineer.&amp;quot;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Sure, some new things are cool. &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Sturgeon%27s_law&quot;&gt;But most of the stuff is useless crap&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I love boring stuff:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Pen &amp;amp; Paper&lt;&#x2F;li&gt;
&lt;li&gt;Water&lt;&#x2F;li&gt;
&lt;li&gt;Oats and rice&lt;&#x2F;li&gt;
&lt;li&gt;Biking and weightlifting&lt;&#x2F;li&gt;
&lt;li&gt;Thinkpads&lt;&#x2F;li&gt;
&lt;li&gt;Vim&lt;&#x2F;li&gt;
&lt;li&gt;Django and SQLite&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Find the trackers on your smartphone with Warden</title>
        <published>2022-02-10T00:00:00+00:00</published>
        <updated>2022-02-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-02-10/" type="text/html"/>
        <id>https://miku86.com/2022-02-10/</id>
        
        <content type="html">&lt;p&gt;Which trackers do your smartphone apps have?&lt;&#x2F;p&gt;
&lt;p&gt;You can check this with Warden.&lt;&#x2F;p&gt;
&lt;p&gt;It is free and open-source.&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;AuroraOSS&#x2F;AppWarden&quot;&gt;Code&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;AuroraOSS&#x2F;AppWarden&#x2F;uploads&#x2F;f3be7974576a2d5f3e0e694ab8da8ebd&#x2F;AppWarden_v1.0.3.apk&quot;&gt;Download&lt;&#x2F;a&gt; - You need to enable the installation from unknown sources.&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;p&gt;Maybe this will show you, how privacy-invasive most of your favorite apps are.&lt;&#x2F;p&gt;
&lt;p&gt;People told me they&#x27;ve found over 100 trackers on their devices...&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Privat-o-Mat &#x2F; Privacymeter</title>
        <published>2022-02-07T00:00:00+00:00</published>
        <updated>2022-02-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-02-07/" type="text/html"/>
        <id>https://miku86.com/2022-02-07/</id>
        
        <content type="html">&lt;p&gt;I&#x27;ve found a great tool on mastodon with which you can test your privacy awareness - &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;privat-o-mat.de&#x2F;&quot;&gt;privat-o-mat&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;You can change the language from German to English at the top of the page.&lt;&#x2F;p&gt;
&lt;p&gt;My privacy weaknesses are:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;payments: I like to pay with my giro card so that I don&#x27;t have to write some sort of household book to manage my finances&lt;&#x2F;li&gt;
&lt;li&gt;shopping: I do online shopping instead of offline shopping&lt;&#x2F;li&gt;
&lt;li&gt;(dating apps: if I wouldn&#x27;t have the best wife in the world, I would give a dating app some personal details)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Replacing Nextcloud with Radicale + Syncthing</title>
        <published>2022-02-01T00:00:00+00:00</published>
        <updated>2022-02-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-02-01/" type="text/html"/>
        <id>https://miku86.com/2022-02-01/</id>
        
        <content type="html">&lt;p&gt;I used &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nextcloud.com&quot;&gt;Nextcloud&lt;&#x2F;a&gt; for ~2 years now.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s awesome. Actually everything you need to self-host your cloud for fun and privacy.&lt;&#x2F;p&gt;
&lt;p&gt;But the older I get, the more I simplify my life - I don&#x27;t need to sync all kind of data between dozens of devices.
Data I don&#x27;t create is data I don&#x27;t have to secure.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I haven&#x27;t been using cloud storage for a long time.&lt;&#x2F;p&gt;
&lt;p&gt;I actually only use syncing for having a backup of my phone contacts.
As you know, I use my smartphone only for messaging with Signal and nothing else.&lt;&#x2F;p&gt;
&lt;p&gt;So my current lightweight setup looks like this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;file sync between specific devices: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;syncthing.net&quot;&gt;Syncthing&lt;&#x2F;a&gt; (I rarely use it)&lt;&#x2F;li&gt;
&lt;li&gt;contact and calendar sync: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;radicale.org&quot;&gt;Radicale&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Both together need 80MB of RAM, while Nextcloud needed around 400MB.&lt;&#x2F;p&gt;
&lt;p&gt;Simply life, happy life.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Read Cheapskate&#x27;s Guide</title>
        <published>2022-01-26T00:00:00+00:00</published>
        <updated>2022-01-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-01-26/" type="text/html"/>
        <id>https://miku86.com/2022-01-26/</id>
        
        <content type="html">&lt;p&gt;I just love &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cheapskatesguide.org&quot;&gt;Cheapskate&#x27;s Guide&lt;&#x2F;a&gt;, it&#x27;s a fantastic site.&lt;&#x2F;p&gt;
&lt;p&gt;My favorite articles:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cheapskatesguide.org&#x2F;articles&#x2F;cost-of-technological-illiteracy.html&quot;&gt;The High Cost of Technological Illiteracy in Our Society&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;The top most-used computer operating systems these days are Windows, Android, macOS, IOS, and Chrome. All were designed, not to give the user a great operating system for a reasonable price. They were designed by giant corporations to imprison their users in the ecosystems of those giant companies, so as to maximize their profits. &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cheapskatesguide.org&#x2F;articles&#x2F;computers-and-adulthood.html&quot;&gt;Computers and Adulthood&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Lately, I&#x27;ve just come right out and told my mother that in order to be an adult in our society at this time, you must know how to use a computer. Computer knowledge is something that adults just have--like a telephone, a place to live, a bank account, taxes and yearly tax filings, a car, and a driver&#x27;s license. Without these things it is very difficult to function as an adult in our society. I realize that some adults are without one or two of these things from time to time, but that is a temporary condition. [...] Like many other areas of knowledge that adults have, the better you are with computers, the easier your life will be.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;cheapskatesguide.org&#x2F;articles&#x2F;techno-clutter-farnell.html&quot;&gt;Is techno-clutter ruining your life?&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Those who are brought up to treasure technology for the wonderful human achievement it is, who are masters of it, will buy and carefully maintain only a few devices. They will understand how they work and be able to repair, re-program and repurpose them as they please. Economic value will shift back toward care, maintenance, support and education. When people buy far less it will of course be a disaster for manufacturing (but not necessarily innovation) and for the FOMO anxiety industry. But we already have far, far, far too much of everything and could quite easily put production on hold for a decade. &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;A necessary step is sincere and informed rejection of the low-quality rubbish peddled to us by major brands. All of what we really need from electronic technology can be satisfied with less powerful, older and simpler devices. Instead we fall for tricks that make us buy insecure new gadgets because they are designed to spy on us. Clearly less is more, and better choices, or simply not buying more stuff, is our way to better mental health and a cleaner planet. &lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Gratitude</title>
        <published>2022-01-19T00:00:00+00:00</published>
        <updated>2022-01-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-01-19/" type="text/html"/>
        <id>https://miku86.com/2022-01-19/</id>
        
        <content type="html">&lt;p&gt;I just found an interesting video on Hacker News about &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;invidious.snopyta.org&#x2F;watch?v=yRWmKh13b50&quot;&gt;homeless people in Oakland&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Regarding the population of the city (500k), the amount of homeless shelters just feels unreal.&lt;&#x2F;p&gt;
&lt;p&gt;Thinking about my life, I just feel a lot of gratitude about my situation.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Pi-hole, OpenWrt</title>
        <published>2022-01-15T00:00:00+00:00</published>
        <updated>2022-01-15T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-01-15/" type="text/html"/>
        <id>https://miku86.com/2022-01-15/</id>
        
        <content type="html">&lt;p&gt;In the last few months a lot of my people became interested in getting rid of ads on their devices.&lt;&#x2F;p&gt;
&lt;p&gt;I use &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Special:Search?search=pihole&quot;&gt;Pi-hole&lt;&#x2F;a&gt; for my local network and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;UBlock_Origin&quot;&gt;uBlock Origin&lt;&#x2F;a&gt; on my devices.&lt;&#x2F;p&gt;
&lt;p&gt;Pi-hole is great, because it works network-wide, so you don&#x27;t have to install software on all devices.
And there are devices that are hard to deal with, e.g. new &amp;quot;smart&amp;quot; TVs.&lt;&#x2F;p&gt;
&lt;p&gt;To use Pi-hole, you have to set Pi-hole as your domain name server (DNS), so that it can block shady domains.&lt;&#x2F;p&gt;
&lt;p&gt;But in some of the latest routers you are not allowed to change your DNS (Vodafone...).&lt;&#x2F;p&gt;
&lt;p&gt;This is dangerous, because these companies could block whatever they want to block.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I currently have a look at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;OpenWrt&quot;&gt;OpenWrt&lt;&#x2F;a&gt;.
It&#x27;s a popular open-source operating system for routers.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve already installed it and setup some stuff. It seems to be simple, but mighty.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>New Year&#x27;s Resolutions</title>
        <published>2022-01-01T00:00:00+00:00</published>
        <updated>2022-01-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2022-01-01/" type="text/html"/>
        <id>https://miku86.com/2022-01-01/</id>
        
        <content type="html">&lt;p&gt;... are a scam.&lt;&#x2F;p&gt;
&lt;p&gt;Just kidding.&lt;&#x2F;p&gt;
&lt;p&gt;But they never worked out for me.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-i-do-instead&quot;&gt;What I do (instead)&lt;&#x2F;h2&gt;
&lt;p&gt;I think a lot about &lt;strong&gt;identity&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What kind of person do I want to be?&lt;&#x2F;li&gt;
&lt;li&gt;How does this kind of person behave in their day-to-day life?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example:
&lt;strong&gt;I want to be a healthy person.&lt;&#x2F;strong&gt; A healthy person gets enough sleep, this is why I sleep without an alarm clock. A healthy person does some mobility exercises in the morning. 
A healthy person eats a good amount of protein and fiber in the morning, e.g. oats with protein powder. And so on...&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve come up with some of these ideas about my identity and how to fulfill them.
I track these behaviours and try to give myself feedback from time to time.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;This is a very dynamic, agile approach.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Reusing old hardware</title>
        <published>2021-12-30T00:00:00+00:00</published>
        <updated>2021-12-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-12-30/" type="text/html"/>
        <id>https://miku86.com/2021-12-30/</id>
        
        <content type="html">&lt;p&gt;Over the years, a lot of devices have accumulated at my home.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m currently thinking about use-cases for them.&lt;&#x2F;p&gt;
&lt;p&gt;Some of them are too beefy to just collecting dust, so I probably will sell them.
Others are so old that probably no one will use them, even for free, like a laptop from 2007.&lt;&#x2F;p&gt;
&lt;p&gt;So I searched around on the interweb and found a nice post about &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20190326123955&#x2F;https:&#x2F;&#x2F;www.honestrepair.net&#x2F;index.php&#x2F;2018&#x2F;10&#x2F;24&#x2F;reusing-old-hardware&#x2F;&quot;&gt;reusing old hardware&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The old laptop uses ~0.015kWh, so this comes down to 40€&#x2F;year of power costs (365 * 24 * 0.015kWh * 0.3€&#x2F;kWh).&lt;&#x2F;p&gt;
&lt;p&gt;My raspberry pi uses ~0.003kWh, so this comes down to 8€&#x2F;year.
A new raspberry costs ~80€, so the savings of 32€&#x2F;year in power would be amortized after 2.5 years.&lt;&#x2F;p&gt;
&lt;p&gt;Money-wise it seems to be more reasonable to buy a (used) raspberry pi and use it for a long time.
But it would create more waste and more consumerism.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Changing surroundings</title>
        <published>2021-12-29T00:00:00+00:00</published>
        <updated>2021-12-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-12-29/" type="text/html"/>
        <id>https://miku86.com/2021-12-29/</id>
        
        <content type="html">&lt;p&gt;Back at home after christmas.&lt;&#x2F;p&gt;
&lt;p&gt;Each time I go to visit a different place, I&#x27;m a little bit thrilled.
A new surrounding, new people, new things to see.&lt;&#x2F;p&gt;
&lt;p&gt;Each time I go to come back home, I&#x27;m a little bit thrilled.
A known surrounding, known people, routines and habits.&lt;&#x2F;p&gt;
&lt;p&gt;At home, I love to get up early and work for some hours.
Home is my place of productivity.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Tracking readers?</title>
        <published>2021-12-20T00:00:00+00:00</published>
        <updated>2021-12-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-12-20/" type="text/html"/>
        <id>https://miku86.com/2021-12-20/</id>
        
        <content type="html">&lt;p&gt;From time to time I&#x27;m interested in what my reader would like to read.&lt;&#x2F;p&gt;
&lt;p&gt;But because I don&#x27;t use any tracking, I do not know.&lt;&#x2F;p&gt;
&lt;p&gt;When I have a look at my &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;miku86&quot;&gt;dev.to&lt;&#x2F;a&gt; dashboard, I can see that many readers read very short posts:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;devto-dashboard.png&quot; alt=&quot;dev.to dashboard&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This first post with nearly 100.000 visits is just a 5-step tutorial.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;So there are two questions:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Does the past - which posts got the most visits - tell me anything about what my readers would like to read in the future?&lt;&#x2F;li&gt;
&lt;li&gt;If I would know what my readers like, would I write more of this stuff?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Actually, I don&#x27;t think that tracking every reader is worth the cost - the loss of privacy (you) and the loss of integrity (me).&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Freedom - full circle</title>
        <published>2021-12-11T00:00:00+00:00</published>
        <updated>2021-12-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-12-11/" type="text/html"/>
        <id>https://miku86.com/2021-12-11/</id>
        
        <content type="html">&lt;p&gt;During Covid 19 we are talking a lot about freedom.&lt;&#x2F;p&gt;
&lt;p&gt;For me, freedom exists on an individual and a societal level.&lt;&#x2F;p&gt;
&lt;p&gt;When too many individual people don&#x27;t get vaccinated, 
the society has to suffer.&lt;&#x2F;p&gt;
&lt;p&gt;So there is this kind of real-life freedom in the physical world.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;But there is another kind of freedom.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Many people don&#x27;t care about freedom when they use computing devices.&lt;&#x2F;p&gt;
&lt;p&gt;They use WhatsApp, Instagram, Windows, Office365, MacOS and all this other non-freedom stuff.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Closed_platform&quot;&gt;Walled gardens&lt;&#x2F;a&gt; emerge and no user can escape.&lt;&#x2F;p&gt;
&lt;p&gt;They are customers and&#x2F;or products.&lt;&#x2F;p&gt;
&lt;p&gt;And these users also force other people to use their non-freedom software because of the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Chicken_or_the_egg&quot;&gt;chicken or the egg problem&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;But I love freedom.&lt;&#x2F;p&gt;
&lt;p&gt;I want to ...&lt;&#x2F;p&gt;
&lt;li&gt;run the software where ever I want to run it -  this is freedom&lt;&#x2F;li&gt;
&lt;li&gt;add a feature - this is freedom&lt;&#x2F;li&gt;
&lt;li&gt;delete a feature (e.g. spy tools) - this is freedom&lt;&#x2F;li&gt;
&lt;li&gt;change the color of some feature - this is freedom&lt;&#x2F;li&gt;
&lt;li&gt;look under the hood to see how it works - this is freedom&lt;&#x2F;li&gt;
&lt;li&gt;send it to a friend - this is freedom&lt;&#x2F;li&gt;
&lt;li&gt;...&lt;&#x2F;li&gt;
&lt;p&gt;This is why &lt;a href=&quot;&#x2F;uses&#x2F;&quot;&gt;I use free(dom) software&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Deleting WhatsApp -  lessons learned</title>
        <published>2021-12-07T00:00:00+00:00</published>
        <updated>2021-12-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-12-07/" type="text/html"/>
        <id>https://miku86.com/2021-12-07/</id>
        
        <content type="html">&lt;p&gt;&lt;a href=&quot;&#x2F;2021-04-03&quot;&gt;I deleted WhatsApp some months ago&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I just found out, that over these 8 months at least 5 people still sent me messages on WhatsApp.&lt;&#x2F;p&gt;
&lt;p&gt;So what&#x27;s the deal?&lt;&#x2F;p&gt;
&lt;p&gt;When you delete your WhatsApp account, &lt;em&gt;but&lt;&#x2F;em&gt; people do not delete the chat with you,
they can simply continue to message you.&lt;&#x2F;p&gt;
&lt;p&gt;But the messages never get delivered.&lt;&#x2F;p&gt;
&lt;p&gt;Some people recognize this (because there is only one of the two checkmarks),
but some do not.&lt;&#x2F;p&gt;
&lt;p&gt;It seems many people never delete chats.&lt;&#x2F;p&gt;
&lt;p&gt;So my lessons learned:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;when you delete your WhatsApp, send a broadcast to all people that you&#x27;ll delete it&lt;&#x2F;li&gt;
&lt;li&gt;also tell them, that they should delete your chat with them&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Hope that helps.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Time flies</title>
        <published>2021-12-04T00:00:00+00:00</published>
        <updated>2021-12-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-12-04/" type="text/html"/>
        <id>https://miku86.com/2021-12-04/</id>
        
        <content type="html">&lt;p&gt;The older I get, the more I perceive time flies by.&lt;&#x2F;p&gt;
&lt;p&gt;Totally lost my publishing habit.&lt;&#x2F;p&gt;
&lt;p&gt;Work - food - nap - sideprojects - gym - sleep.&lt;&#x2F;p&gt;
&lt;p&gt;Publishing just costs me like 5min, 
but somehow I could not handle it.&lt;&#x2F;p&gt;
&lt;p&gt;Until now.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>What to do next?</title>
        <published>2021-11-24T00:00:00+00:00</published>
        <updated>2021-11-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-11-24/" type="text/html"/>
        <id>https://miku86.com/2021-11-24/</id>
        
        <content type="html">&lt;p&gt;What should I do next? A or B or C?&lt;&#x2F;p&gt;
&lt;p&gt;Where do A, B and C come from?&lt;&#x2F;p&gt;
&lt;p&gt;Each time I think about these kind of questions, I end up with thinking about the purpose of (my) life.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I try to think backwards.&lt;&#x2F;p&gt;
&lt;p&gt;I ask myself questions like:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What should people say at my funeral?&lt;&#x2F;li&gt;
&lt;li&gt;What do I want to be known for?&lt;&#x2F;li&gt;
&lt;li&gt;What can I pass on to the next generation of people?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;With these (never-ending) answers in mind, I try to work on stuff that leads to fulfilling these answers.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Cryptos: Intro</title>
        <published>2021-11-10T00:00:00+00:00</published>
        <updated>2021-11-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-11-10/" type="text/html"/>
        <id>https://miku86.com/2021-11-10/</id>
        
        <content type="html">&lt;p&gt;Hey folks,&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m into learning a whole new topic in-depth: cryptocurrencies.&lt;&#x2F;p&gt;
&lt;p&gt;In public. #learninpublic&lt;&#x2F;p&gt;
&lt;p&gt;I like to learn, I like to explain.&lt;&#x2F;p&gt;
&lt;p&gt;It helps me to deepen my knowledge.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I share this stuff with you.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;why&quot;&gt;Why?&lt;&#x2F;h2&gt;
&lt;p&gt;In the last few months, a lot of my friends have been talking about crypto.&lt;&#x2F;p&gt;
&lt;p&gt;But when I ask them questions about it, because I want to learn from them, they literally know nothing, zero, niente about it.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Q: Oh cool, why did you buy this cryptocurrency?
&lt;br&gt;
A: A Youtuber talked about it.&lt;&#x2F;p&gt;
&lt;p&gt;Q: Which &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Consensus_(computer_science)?lang=en&quot;&gt;consensus mechanism&lt;&#x2F;a&gt; does this cryptocurrency use?
&lt;br&gt;
A: Eehm, what is a &amp;quot;consensus mechanism&amp;quot;?&lt;&#x2F;p&gt;
&lt;p&gt;Q: What is your investment strategy (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Investment_management?lang=en&quot;&gt;1&lt;&#x2F;a&gt;, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Asset_allocation?lang=en&quot;&gt;2&lt;&#x2F;a&gt;)?
&lt;br&gt;
A: I don&#x27;t have one.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;So most of the time I think they just want to ride the hype-train. 
Some uncle&#x27;s step-daughter&#x27;s friend become a millionaire, so maybe there is a lof of &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wikiless.tiekoetter.com&#x2F;wiki&#x2F;Fear_of_missing_out?lang=en&quot;&gt;fear-of-missing-out&lt;&#x2F;a&gt; involved.&lt;&#x2F;p&gt;
&lt;p&gt;&amp;quot;I have to work 9-5, and this non-intelligent guy made some 10.000 bucks, I don&#x27;t want to miss this next opportunity!&amp;quot;&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t get me wrong, this is a normal human emotion, so it is not bad.
I just think making bad decisions based on this emotion is not so fruitful.&lt;&#x2F;p&gt;
&lt;p&gt;Actually, I think this is &lt;strong&gt;very dangerous&lt;&#x2F;strong&gt;. 
Because this nurtures a very dangerous habit: acting based on bad decision-making patterns.&lt;&#x2F;p&gt;
&lt;p&gt;And I think one of the worst decision-making patterns is: not knowing the fundamentals.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I want to talk about the &lt;strong&gt;basics of cryptocurrencies&lt;&#x2F;strong&gt; -  as a software developer.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;our-objectives&quot;&gt;Our objectives&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Which problems do we want to solve with cryptocurrencies?&lt;&#x2F;li&gt;
&lt;li&gt;What is a ledger (e.g. a blockchain)?&lt;&#x2F;li&gt;
&lt;li&gt;Who decides what the state of the ledger is?&lt;&#x2F;li&gt;
&lt;li&gt;What is a wallet?&lt;&#x2F;li&gt;
&lt;li&gt;How does a transaction work?&lt;&#x2F;li&gt;
&lt;li&gt;What is a cryptocurrency?&lt;&#x2F;li&gt;
&lt;li&gt;How do I buy cryptocurrency?&lt;&#x2F;li&gt;
&lt;li&gt;...&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;&lt;strong&gt;One simple disclaimer&lt;&#x2F;strong&gt;: Always double-check your informations, also my posts - everything.
If you don&#x27;t understand it, read up about it, ask questions (&amp;quot;What does X mean?&amp;quot;), paraphrase in your own words (&amp;quot;So this means, that ...?&amp;quot;).
Don&#x27;t act like a fool, always understand the underlying fundamentals.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How to diff two files</title>
        <published>2021-11-08T00:00:00+00:00</published>
        <updated>2021-11-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-11-08/" type="text/html"/>
        <id>https://miku86.com/2021-11-08/</id>
        
        <content type="html">&lt;p&gt;Just wanted to check which packages I&#x27;ve installed on my different Linux devices,
so I wrote the package names into a file (&lt;code&gt;pacman -Q &amp;gt; packages.txt&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;But how to find the differences?&lt;&#x2F;p&gt;
&lt;p&gt;Use git: &lt;code&gt;git diff --no-index --word-diff a.txt b.txt&lt;&#x2F;code&gt; (&lt;code&gt;a.txt&lt;&#x2F;code&gt; and &lt;code&gt;b.txt&lt;&#x2F;code&gt; are the files you saved the package names in)&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;16683121&#x2F;git-diff-between-two-different-files&quot;&gt;Source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Added old blog posts</title>
        <published>2021-11-07T00:00:00+00:00</published>
        <updated>2021-11-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-11-07/" type="text/html"/>
        <id>https://miku86.com/2021-11-07/</id>
        
        <content type="html">&lt;p&gt;I finally added my old blog posts.&lt;&#x2F;p&gt;
&lt;p&gt;I had to use a lot of regex magic to modify the frontmatter of each post (e.g. converting &lt;code&gt;---&lt;&#x2F;code&gt; to &lt;code&gt;+++&lt;&#x2F;code&gt;),
but now it is done, Zola was able to compile each post.&lt;&#x2F;p&gt;
&lt;p&gt;I think some links will be broken, because I changed some internal paths, but I think a not-so-lazy person can help themself.&lt;&#x2F;p&gt;
&lt;p&gt;If you find some broken links, typos or have some feedback,
send me an email.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Linux</title>
        <published>2021-11-05T00:00:00+00:00</published>
        <updated>2021-11-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-11-05/" type="text/html"/>
        <id>https://miku86.com/2021-11-05/</id>
        
        <content type="html">&lt;p&gt;I use Linux for some years know.&lt;&#x2F;p&gt;
&lt;p&gt;Most questions I get are 95% the same.&lt;&#x2F;p&gt;
&lt;p&gt;This is an open-end collection of my knowledge in simple language.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;notes-and-personal-thoughts&quot;&gt;Notes and personal thoughts&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Linux is the kernel, the inner core&lt;&#x2F;li&gt;
&lt;li&gt;some drivers (for graphic cards, wifi etc.) are inside the kernel&lt;&#x2F;li&gt;
&lt;li&gt;desktop environments (Gnome, KDE etc.) make the experience more convenient and pretty (how windows look, status bar etc.)&lt;&#x2F;li&gt;
&lt;li&gt;additional software makes life easier&lt;&#x2F;li&gt;
&lt;li&gt;kernel (Linux) + desktop environment + additonal software = Linux distribution (Ubuntu, Mint etc.)&lt;&#x2F;li&gt;
&lt;li&gt;Linux is written in C, so it is fast, but a lot of bugs stem from the fact that it is not memory-safe&lt;&#x2F;li&gt;
&lt;li&gt;I don&#x27;t use a desktop environment, just a window manager (i3), no status bar etc.&lt;&#x2F;li&gt;
&lt;li&gt;I use many small tools, e.g. vim as editor, ranger as file manager&lt;&#x2F;li&gt;
&lt;li&gt;less packages&#x2F;tools =&amp;gt; less complexity =&amp;gt; easier life (I have ~500 packages installed)&lt;&#x2F;li&gt;
&lt;li&gt;learn the fundamentals first (folder structure, commandline etc.), then choose your distro&lt;&#x2F;li&gt;
&lt;li&gt;better learn &lt;code&gt;sed&lt;&#x2F;code&gt; than &lt;code&gt;grep&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;if you need help, read the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;&quot;&gt;Arch Wiki&lt;&#x2F;a&gt; (general knowledge about Linux)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;tips-and-tricks&quot;&gt;Tips and tricks&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;show resolution of current display: &lt;code&gt;xrandr | grep &amp;quot;current&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;get current date and time: &lt;code&gt;date&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;search for a &lt;code&gt;string&lt;&#x2F;code&gt; in all files in a folder &lt;code&gt;grep -R &amp;quot;string&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;links&quot;&gt;Links&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Linux&quot;&gt;Wiki: Linux&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.kernel.org&#x2F;category&#x2F;faq.html&quot;&gt;FAQ Linux&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Vim love</title>
        <published>2021-11-01T00:00:00+00:00</published>
        <updated>2021-11-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-11-01/" type="text/html"/>
        <id>https://miku86.com/2021-11-01/</id>
        
        <content type="html">&lt;p&gt;I love vim.&lt;&#x2F;p&gt;
&lt;p&gt;Although I used vim for some months now, I always did some tasks with vscodium, e.g.:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;removing leading&#x2F;trailing characters in multiple lines&lt;&#x2F;li&gt;
&lt;li&gt;search and replace&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;But because opening files in vim is so much faster than in vscodium, especially if I only want to edit one file, I searched for some vim-esque solutions:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;removing in multiple lines: go into visual block mode (&lt;code&gt;ctrl + v&lt;&#x2F;code&gt;), highlight the correct block, do your thing (e.g. &lt;code&gt;x&lt;&#x2F;code&gt; to remove character)&lt;&#x2F;li&gt;
&lt;li&gt;removing in multiple lines: go into visual line mode (&lt;code&gt;shift + v&lt;&#x2F;code&gt;), highlight the correct lines, do your thing in command mode (e.g. &lt;code&gt;:&#x27;&amp;lt;,&#x27;&amp;gt;norm x&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;search and replace: go into command mode (&lt;code&gt;:&lt;&#x2F;code&gt;), search in all lines (&lt;code&gt;%&lt;&#x2F;code&gt;), substitute &lt;code&gt;vim&lt;&#x2F;code&gt; with &lt;code&gt;emacs&lt;&#x2F;code&gt; and ask on each occurrency (&lt;code&gt;s&#x2F;vim&#x2F;emacs&#x2F;c&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So as we can see, there are multiple solutions for different problems.&lt;&#x2F;p&gt;
&lt;p&gt;But actually both problems can get destructured into simple steps.&lt;&#x2F;p&gt;
&lt;p&gt;I think this kind of thinking also leads to better problem solving.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Reimagining Capitalism</title>
        <published>2021-10-25T00:00:00+00:00</published>
        <updated>2021-10-25T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-25/" type="text/html"/>
        <id>https://miku86.com/2021-10-25/</id>
        
        <content type="html">&lt;p&gt;I just wanted to grab a copy of this book, because I&#x27;ve read an article about it.&lt;&#x2F;p&gt;
&lt;p&gt;I think most books are time-wasters, because a lot of stuff has already been said,
or the author has to create 300 pages (&amp;quot;people want to get something for their money&amp;quot;) where 20 or 50 pages also would have been enough.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I just had a quick look over to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.goodreads.com&#x2F;review&#x2F;show&#x2F;3727698559&quot;&gt;some reviews&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;So I successfully deleted this book from my reading list.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Hosting in Europe</title>
        <published>2021-10-24T00:00:00+00:00</published>
        <updated>2021-10-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-24/" type="text/html"/>
        <id>https://miku86.com/2021-10-24/</id>
        
        <content type="html">&lt;p&gt;When I read about hosting providers, e.g. for a virtual privater server, there are &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Category:Cloud_computing_providers&quot;&gt;a lot of companies&lt;&#x2F;a&gt;: AWS, Digital Ocean, Vultr, Linode etc.&lt;&#x2F;p&gt;
&lt;p&gt;Many of them are based in the US, so they don&#x27;t care about my European freedom and privacy rights.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I&#x27;ll have a look at hosting provides in Europe.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;companies&quot;&gt;Companies&lt;&#x2F;h2&gt;
&lt;p&gt;Hetzner, Netcup and Contabo are based in Germany, OVH is based in France.&lt;&#x2F;p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Company&lt;&#x2F;th&gt;&lt;th&gt;Country&lt;&#x2F;th&gt;&lt;th&gt;Employees&lt;&#x2F;th&gt;&lt;th&gt;Revenue&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;Germany&lt;&#x2F;td&gt;&lt;td&gt;~300&lt;&#x2F;td&gt;&lt;td&gt;~250Mio&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Contabo&lt;&#x2F;td&gt;&lt;td&gt;Germany&lt;&#x2F;td&gt;&lt;td&gt;~50&lt;&#x2F;td&gt;&lt;td&gt;~25Mio&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;OVH&lt;&#x2F;td&gt;&lt;td&gt;France&lt;&#x2F;td&gt;&lt;td&gt;~600&lt;&#x2F;td&gt;&lt;td&gt;~600Mio&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Netcup&lt;&#x2F;td&gt;&lt;td&gt;Germany&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;p&gt;Numbers are from &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.bundesanzeiger.de&quot;&gt;Bundesanzeiger&lt;&#x2F;a&gt; and Wikipedia.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;products&quot;&gt;Products&lt;&#x2F;h2&gt;
&lt;p&gt;Sorted by CPU cores, RAM, Price.&lt;&#x2F;p&gt;
&lt;p&gt;I looked for the prices for a contract period of 0&#x2F;1 months, because I want to stay flexible. If you find different prices, this is probably through different default contract periods. Also watch out for setup fees, e.g. on Contabo you have to pay 4,99€ for a contract period of 0 months.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;1-cores&quot;&gt;1 Cores&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Company&lt;&#x2F;th&gt;&lt;th&gt;Price (month)&lt;&#x2F;th&gt;&lt;th&gt;Cores&lt;&#x2F;th&gt;&lt;th&gt;RAM&lt;&#x2F;th&gt;&lt;th&gt;Disk&lt;&#x2F;th&gt;&lt;th&gt;Traffic&lt;&#x2F;th&gt;&lt;th&gt;Contract&lt;&#x2F;th&gt;&lt;th&gt;Notes&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Netcup&lt;&#x2F;td&gt;&lt;td&gt;2,69€&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;2 GB&lt;&#x2F;td&gt;&lt;td&gt;20 GB&lt;&#x2F;td&gt;&lt;td&gt;40 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;4,15€&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;2 GB&lt;&#x2F;td&gt;&lt;td&gt;20 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;OVH&lt;&#x2F;td&gt;&lt;td&gt;5,95€&lt;&#x2F;td&gt;&lt;td&gt;1&lt;&#x2F;td&gt;&lt;td&gt;2 GB&lt;&#x2F;td&gt;&lt;td&gt;40 GB (NVME)&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;2-cores&quot;&gt;2 Cores&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Company&lt;&#x2F;th&gt;&lt;th&gt;Price (month)&lt;&#x2F;th&gt;&lt;th&gt;Cores&lt;&#x2F;th&gt;&lt;th&gt;RAM&lt;&#x2F;th&gt;&lt;th&gt;Disk&lt;&#x2F;th&gt;&lt;th&gt;Traffic&lt;&#x2F;th&gt;&lt;th&gt;Contract&lt;&#x2F;th&gt;&lt;th&gt;Notes&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;4,75€&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;td&gt;2 GB&lt;&#x2F;td&gt;&lt;td&gt;40 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Netcup&lt;&#x2F;td&gt;&lt;td&gt;5,29€&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;td&gt;4 GB&lt;&#x2F;td&gt;&lt;td&gt;40 GB&lt;&#x2F;td&gt;&lt;td&gt;40 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;5,83€&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;td&gt;4 GB&lt;&#x2F;td&gt;&lt;td&gt;40 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;OVH&lt;&#x2F;td&gt;&lt;td&gt;11,90€&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;td&gt;4 GB&lt;&#x2F;td&gt;&lt;td&gt;80 GB (NVME)&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;10,59€&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;td&gt;8 GB&lt;&#x2F;td&gt;&lt;td&gt;80 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Netcup&lt;&#x2F;td&gt;&lt;td&gt;10,00€&lt;&#x2F;td&gt;&lt;td&gt;2&lt;&#x2F;td&gt;&lt;td&gt;8 GB&lt;&#x2F;td&gt;&lt;td&gt;160 GB&lt;&#x2F;td&gt;&lt;td&gt;80 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;4-cores&quot;&gt;4 Cores&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Company&lt;&#x2F;th&gt;&lt;th&gt;Price (month)&lt;&#x2F;th&gt;&lt;th&gt;Cores&lt;&#x2F;th&gt;&lt;th&gt;RAM&lt;&#x2F;th&gt;&lt;th&gt;Disk&lt;&#x2F;th&gt;&lt;th&gt;Traffic&lt;&#x2F;th&gt;&lt;th&gt;Contract&lt;&#x2F;th&gt;&lt;th&gt;Notes&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Contabo&lt;&#x2F;td&gt;&lt;td&gt;4,99€&lt;&#x2F;td&gt;&lt;td&gt;4&lt;&#x2F;td&gt;&lt;td&gt;8 GB&lt;&#x2F;td&gt;&lt;td&gt;200 GB&lt;&#x2F;td&gt;&lt;td&gt;32 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;Setup fee&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;14,76€&lt;&#x2F;td&gt;&lt;td&gt;4&lt;&#x2F;td&gt;&lt;td&gt;8 GB&lt;&#x2F;td&gt;&lt;td&gt;160 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;OVH&lt;&#x2F;td&gt;&lt;td&gt;23,80€&lt;&#x2F;td&gt;&lt;td&gt;4&lt;&#x2F;td&gt;&lt;td&gt;8 GB&lt;&#x2F;td&gt;&lt;td&gt;160 GB (NVME)&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Netcup&lt;&#x2F;td&gt;&lt;td&gt;14,30€&lt;&#x2F;td&gt;&lt;td&gt;4&lt;&#x2F;td&gt;&lt;td&gt;16 GB&lt;&#x2F;td&gt;&lt;td&gt;320 GB&lt;&#x2F;td&gt;&lt;td&gt;80 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;18,92€&lt;&#x2F;td&gt;&lt;td&gt;4&lt;&#x2F;td&gt;&lt;td&gt;16 GB&lt;&#x2F;td&gt;&lt;td&gt;160 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h3 id=&quot;6-8-cores&quot;&gt;6&#x2F;8 Cores&lt;&#x2F;h3&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Company&lt;&#x2F;th&gt;&lt;th&gt;Price (month)&lt;&#x2F;th&gt;&lt;th&gt;Cores&lt;&#x2F;th&gt;&lt;th&gt;RAM&lt;&#x2F;th&gt;&lt;th&gt;Disk&lt;&#x2F;th&gt;&lt;th&gt;Traffic&lt;&#x2F;th&gt;&lt;th&gt;Contract&lt;&#x2F;th&gt;&lt;th&gt;Notes&lt;&#x2F;th&gt;&lt;&#x2F;tr&gt;&lt;&#x2F;thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Contabo&lt;&#x2F;td&gt;&lt;td&gt;8,99€&lt;&#x2F;td&gt;&lt;td&gt;6&lt;&#x2F;td&gt;&lt;td&gt;16 GB&lt;&#x2F;td&gt;&lt;td&gt;400 GB&lt;&#x2F;td&gt;&lt;td&gt;32 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;Setup fee&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Netcup&lt;&#x2F;td&gt;&lt;td&gt;20,80€&lt;&#x2F;td&gt;&lt;td&gt;6&lt;&#x2F;td&gt;&lt;td&gt;24 GB&lt;&#x2F;td&gt;&lt;td&gt;600 GB&lt;&#x2F;td&gt;&lt;td&gt;80 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;27,25€&lt;&#x2F;td&gt;&lt;td&gt;8&lt;&#x2F;td&gt;&lt;td&gt;16 GB&lt;&#x2F;td&gt;&lt;td&gt;240 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Contabo&lt;&#x2F;td&gt;&lt;td&gt;14,99€&lt;&#x2F;td&gt;&lt;td&gt;8&lt;&#x2F;td&gt;&lt;td&gt;30 GB&lt;&#x2F;td&gt;&lt;td&gt;800 GB&lt;&#x2F;td&gt;&lt;td&gt;32 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;Setup fee&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Netcup&lt;&#x2F;td&gt;&lt;td&gt;27,30€&lt;&#x2F;td&gt;&lt;td&gt;8&lt;&#x2F;td&gt;&lt;td&gt;32 GB&lt;&#x2F;td&gt;&lt;td&gt;800 GB&lt;&#x2F;td&gt;&lt;td&gt;80 TB&lt;&#x2F;td&gt;&lt;td&gt;0 months&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;tr&gt;&lt;td&gt;Hetzner&lt;&#x2F;td&gt;&lt;td&gt;35,58€&lt;&#x2F;td&gt;&lt;td&gt;8&lt;&#x2F;td&gt;&lt;td&gt;32 GB&lt;&#x2F;td&gt;&lt;td&gt;240 GB&lt;&#x2F;td&gt;&lt;td&gt;20 TB&lt;&#x2F;td&gt;&lt;td&gt;?&lt;&#x2F;td&gt;&lt;td&gt;&lt;&#x2F;td&gt;&lt;&#x2F;tr&gt;
&lt;&#x2F;tbody&gt;&lt;&#x2F;table&gt;
&lt;h2 id=&quot;links&quot;&gt;Links&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.hetzner.de&#x2F;&quot;&gt;Hetzner&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.netcup.de&#x2F;&quot;&gt;Netcup&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ovh.de&#x2F;&quot;&gt;OVH&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;contabo.de&#x2F;&quot;&gt;Contabo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Be the change you want to see</title>
        <published>2021-10-23T00:00:00+00:00</published>
        <updated>2021-10-23T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-23/" type="text/html"/>
        <id>https://miku86.com/2021-10-23/</id>
        
        <content type="html">&lt;p&gt;Instead of hoping that other people, politicians or businesses change the world,
do it yourself.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nitter.snopyta.org&#x2F;zachklein&#x2F;status&#x2F;1450113164775870468&quot;&gt;Zach Klein&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Analog vs. digital</title>
        <published>2021-10-20T00:00:00+00:00</published>
        <updated>2021-10-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-20/" type="text/html"/>
        <id>https://miku86.com/2021-10-20/</id>
        
        <content type="html">&lt;p&gt;My devices are very well organized:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I have no desktop icons&lt;&#x2F;li&gt;
&lt;li&gt;I delete stuff all the time&lt;&#x2F;li&gt;
&lt;li&gt;my backups are 200MB small&lt;&#x2F;li&gt;
&lt;li&gt;I don&#x27;t open more than ~5 browser tabs and close them after the task at hand
...&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;But sometimes I struggle with my todo lists. Yes, I have multiple lists.&lt;&#x2F;p&gt;
&lt;p&gt;I write down stuff on my computers. On my smartphones. On paper. On a whiteboard.&lt;&#x2F;p&gt;
&lt;p&gt;And suddenly, I have 4 files of todos, sometimes in a general folder, sometimes in a project folder.&lt;&#x2F;p&gt;
&lt;p&gt;Weeks later, I find these notes and feel dumb and guilty.&lt;&#x2F;p&gt;
&lt;p&gt;This time, I took one step back and asked myself &amp;quot;Why do I struggle?&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;And the answer is: Because I have multiple sources of incoming todos, but they are distributed all over the place.&lt;&#x2F;p&gt;
&lt;p&gt;So how could I solve this challenge?&lt;&#x2F;p&gt;
&lt;p&gt;Digital: I could write down my todos on 5 devices and keep it in sync. I tried this multiple times.
And I always failed after some weeks or months.
The biggest problem was the &amp;quot;flat hierarchy&amp;quot; on my devices: With a dozen of programs on my devices, a todo-list is not noticeable.
It just sits there until I forget it. And what happens when I&#x27;m not in-front of a device?&lt;&#x2F;p&gt;
&lt;p&gt;Analog: I could write down my todos on a piece of paper. This is what I currently try to implement.
My stack looks like this: the cardboard packaging of an old smartphone, some post-its, a pencil.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nitter.snopyta.org&#x2F;levelsio&#x2F;status&#x2F;908833499452514309&quot;&gt;Pieter Levels has a simple explanation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s see how this will work out!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>I own my phones</title>
        <published>2021-10-19T00:00:00+00:00</published>
        <updated>2021-10-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-19/" type="text/html"/>
        <id>https://miku86.com/2021-10-19/</id>
        
        <content type="html">&lt;p&gt;I own 2 phones.&lt;&#x2F;p&gt;
&lt;p&gt;Phone 1 is my emergency phone. It is located in the entrance hall. Whenever I leave, I think briefly about whether I should take it with me, e.g. if I drive by car and there could be some sort of emergency. When I stay in town, I rarely take it with me. It is a used Sony Xperia Z1 Compact back from 2014 with &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;LineageOS&quot;&gt;Lineage OS&lt;&#x2F;a&gt;, no Google apps and most other apps deleted. As I said, it just exists for emergencies, so it has a SIM card to do some emergency calls. Because it is mostly off, I only have to charge it once every 2-3 weeks.&lt;&#x2F;p&gt;
&lt;p&gt;Phone 2 is my &amp;quot;leisure phone&amp;quot;. It is located in the laundry room. Whenever I feel the urge to message someone, I have to go downstairs. I do my tasks, e.g. checking my messages and then I leave it alone. It is an old Motorola phone from 2015 with Lineage OS, no Google apps. I use the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Signal_(software)&quot;&gt;Signal&lt;&#x2F;a&gt; messenger and the default Lineage OS apps for calendar and contacts. It has no SIM card. It is &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Moto_E_(2nd_generation)&quot;&gt;fairly slow&lt;&#x2F;a&gt;, but that&#x27;s a feature, not a bug: It is too slow to be enjoyable, so I just do my messaging stuff and leave it alone. If I need to sync some data (ideas, images), I use &lt;a href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;2021-10-19&#x2F;:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Syncthing&quot;&gt;syncthing&lt;&#x2F;a&gt; in my home wifi.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;So all in all, I own my phones, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;libredd.it&#x2F;r&#x2F;nosurf&#x2F;comments&#x2F;khwcb7&#x2F;a_life_wasted&#x2F;&quot;&gt;they don&#x27;t own me&lt;&#x2F;a&gt;.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Why do I use two phones instead of one?&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Phone 1 is very fast, so this would increase the probability that I would do some addictive stuff&lt;&#x2F;li&gt;
&lt;li&gt;Phone 1 doesn&#x27;t have a bumper case, so I don&#x27;t want to increase the probability to break it&lt;&#x2F;li&gt;
&lt;li&gt;Phone 2 has a broken SIM card reader, so I can&#x27;t use it for calling&lt;&#x2F;li&gt;
&lt;li&gt;I don&#x27;t want to have a single point of failure (losing the phone)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Framework vs. blueprint</title>
        <published>2021-10-18T00:00:00+00:00</published>
        <updated>2021-10-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-18/" type="text/html"/>
        <id>https://miku86.com/2021-10-18/</id>
        
        <content type="html">&lt;p&gt;Sometimes I find myself searching for a blueprint.&lt;&#x2F;p&gt;
&lt;p&gt;&amp;quot;3 steps to stay healthy &#x2F; find brotherhood &#x2F; become rich &#x2F; have a great relationship etc.&amp;quot;&lt;&#x2F;p&gt;
&lt;p&gt;Then I stop and ask myself: Is this who I want to be? A person who needs a babysitter for life?&lt;&#x2F;p&gt;
&lt;p&gt;What happens when the blueprint somehow doesn&#x27;t work?&lt;&#x2F;p&gt;
&lt;p&gt;What happens when I skip one step?&lt;&#x2F;p&gt;
&lt;p&gt;Is it me or the blueprint?&lt;&#x2F;p&gt;
&lt;p&gt;How does a blueprint handle change?&lt;&#x2F;p&gt;
&lt;p&gt;Why do I even care about a blueprint? Fear? Laziness? Need for security?&lt;&#x2F;p&gt;
&lt;p&gt;One of the best skills to master is robustness and antifragility.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;That&#x27;s why I think in frameworks instead of blueprints.&lt;&#x2F;p&gt;
&lt;p&gt;Each project&#x2F;goal I have has some underlying fundamentals:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Staying healthy: biology, psychology&lt;&#x2F;li&gt;
&lt;li&gt;Finding brotherhood: psychology, sociology&lt;&#x2F;li&gt;
&lt;li&gt;Becoming rich: psychology, economy&lt;&#x2F;li&gt;
&lt;li&gt;Having a great relationship: psychology, sociology, communication&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As we can see, there is a lot of science involved, e.g. psychology is everywhere.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I read scientific books.&lt;&#x2F;p&gt;
&lt;p&gt;And then I create my framework - a set of rules and habits with a contextual note.&lt;&#x2F;p&gt;
&lt;p&gt;For example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;when I am with people, I don&#x27;t have my phone nearby me&lt;&#x2F;li&gt;
&lt;li&gt;when I am with people, I try not to judge them&lt;&#x2F;li&gt;
&lt;li&gt;when I sleep, I don&#x27;t use an alarm&lt;&#x2F;li&gt;
&lt;li&gt;when I eat, I do nothing else&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The difference to a blueprint is the fact, that all these things are based on my contextual knowledge about myself.&lt;&#x2F;p&gt;
&lt;p&gt;They also have a high probability to work, because they are backed by science.&lt;&#x2F;p&gt;
&lt;p&gt;These are the things that work for me. Maybe not for you.&lt;&#x2F;p&gt;
&lt;p&gt;If a tool does not work, I use another one.&lt;&#x2F;p&gt;
&lt;p&gt;I am open for change.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Holocracy, Open-Book Management</title>
        <published>2021-10-16T00:00:00+00:00</published>
        <updated>2021-10-16T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-16/" type="text/html"/>
        <id>https://miku86.com/2021-10-16/</id>
        
        <content type="html">&lt;p&gt;Today I decluttered my collection of interesting articles.&lt;&#x2F;p&gt;
&lt;p&gt;There was this one article about &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Holacracy&quot;&gt;holacracy&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I read about this idea some years ago in an interview about &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tony_Hsieh&quot;&gt;Tony Hsieh&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;As a software engineer, I oftentimes think about ideas like agility, change and transparency.&lt;&#x2F;p&gt;
&lt;p&gt;Software is connected to business processes.&lt;&#x2F;p&gt;
&lt;p&gt;When a business process changes, we have to be agile enough to adapt the software to the new changes.&lt;&#x2F;p&gt;
&lt;p&gt;So how much do I need to know about the business process and its context?&lt;&#x2F;p&gt;
&lt;p&gt;Is change the default mode of business? Of life?&lt;&#x2F;p&gt;
&lt;p&gt;Which concepts lead to easier handling of change?&lt;&#x2F;p&gt;
&lt;p&gt;This is how I found the concept of &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Open-book_management&quot;&gt;open-book management&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;The basis of open-book management is that the information received by employees should not only help them do their jobs effectively but help them understand how the company is doing as a whole.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;The technique is to give employees all relevant financial information about the company so they can make better decisions as workers.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;This sounds very interesting.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Momentum</title>
        <published>2021-10-15T00:00:00+00:00</published>
        <updated>2021-10-15T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-15/" type="text/html"/>
        <id>https://miku86.com/2021-10-15/</id>
        
        <content type="html">&lt;p&gt;All plans are set up.&lt;&#x2F;p&gt;
&lt;p&gt;Doing this, doing that. Work, leisure, people.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ll do it tomorrow, today I&#x27;m too tired.&lt;&#x2F;p&gt;
&lt;p&gt;And suddenly 2 weeks are gone.&lt;&#x2F;p&gt;
&lt;p&gt;Guilt.&lt;&#x2F;p&gt;
&lt;p&gt;Habits come and go.&lt;&#x2F;p&gt;
&lt;p&gt;Ebb and flow.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Software: Free? Open source?</title>
        <published>2021-10-01T00:00:00+00:00</published>
        <updated>2021-10-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-10-01/" type="text/html"/>
        <id>https://miku86.com/2021-10-01/</id>
        
        <content type="html">&lt;p&gt;When we talk about software, there are terms like &amp;quot;free&amp;quot;, &amp;quot;open source&amp;quot; etc.&lt;&#x2F;p&gt;
&lt;p&gt;What do these terms stand for?&lt;&#x2F;p&gt;
&lt;p&gt;Free software: &amp;quot;Free&amp;quot; stands for freedom. Free software stands for the possibility for users to run, study, change, redistribute, modify the software. &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.gnu.org&#x2F;philosophy&#x2F;free-sw.html&quot;&gt;Official Definition&lt;&#x2F;a&gt;. So this term does &lt;em&gt;not&lt;&#x2F;em&gt; tell you anything about the monetary price of the software.&lt;&#x2F;p&gt;
&lt;p&gt;Open source software: &amp;quot;Open&amp;quot; stands for open access to source code. If you think about free software&#x27;s possibility to modify the software, free software practically always needs to be open source, but open source software does not have to be free software. &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;opensource.org&#x2F;osd&quot;&gt;Official Definition&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Rust</title>
        <published>2021-09-29T00:00:00+00:00</published>
        <updated>2021-09-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-29/" type="text/html"/>
        <id>https://miku86.com/2021-09-29/</id>
        
        <content type="html">&lt;p&gt;Start: 2021-08-20&lt;&#x2F;p&gt;
&lt;p&gt;Last update: 2021-10-05&lt;&#x2F;p&gt;
&lt;h1 id=&quot;common-concepts&quot;&gt;Common Concepts&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;statically typed: must know all types at compile time (but can infer a lot of types)&lt;&#x2F;li&gt;
&lt;li&gt;variables are immutable&lt;&#x2F;li&gt;
&lt;li&gt;variables have a scope and live only in a block (&lt;code&gt;{}&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;types: no implicit coercion&lt;&#x2F;li&gt;
&lt;li&gt;primitive types:
&lt;ul&gt;
&lt;li&gt;4 scalars:
&lt;ul&gt;
&lt;li&gt;integer: signed &lt;code&gt;i8&lt;&#x2F;code&gt; - &lt;code&gt;i128&lt;&#x2F;code&gt;, unsigned &lt;code&gt;u8&lt;&#x2F;code&gt; - &lt;code&gt;u128&lt;&#x2F;code&gt;, smaller number of bits is faster to process, e g. &lt;code&gt;-10&lt;&#x2F;code&gt; as an &lt;code&gt;i8&lt;&#x2F;code&gt; is way shorter than as &lt;code&gt;i128&lt;&#x2F;code&gt;, &lt;code&gt;isize&lt;&#x2F;code&gt; and &lt;code&gt;usize&lt;&#x2F;code&gt; depend on the computer architecture&lt;&#x2F;li&gt;
&lt;li&gt;float&lt;&#x2F;li&gt;
&lt;li&gt;boolean&lt;&#x2F;li&gt;
&lt;li&gt;char: every character has an unicode number, e.g. &lt;code&gt;A&lt;&#x2F;code&gt; is number 65, all chars use 4 bytes of memory, but in a string least amount of memory&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;2 compounds: array (same types), tuple (different types)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;custom types:
&lt;ul&gt;
&lt;li&gt;structs: classic struct, tuple struct, unit struct&lt;&#x2F;li&gt;
&lt;li&gt;enums: allow only some variants, you can use type aliases to refer to enums&lt;&#x2F;li&gt;
&lt;li&gt;constants: unchangeable&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;custom types from standard library:
&lt;ul&gt;
&lt;li&gt;Strings: see in its own chapter&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Vector&lt;&#x2F;code&gt;: growable,&lt;&#x2F;li&gt;
&lt;li&gt;optional type &lt;code&gt;Option&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;error type &lt;code&gt;Result&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;heap allocated pointer &lt;code&gt;Box&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;shadowing vs. &lt;code&gt;mut&lt;&#x2F;code&gt;: can change type, used if you change a number a lot&lt;&#x2F;li&gt;
&lt;li&gt;vector is an growable array&lt;&#x2F;li&gt;
&lt;li&gt;hashmap like js object&lt;&#x2F;li&gt;
&lt;li&gt;each parameter needs explicit type annotation&lt;&#x2F;li&gt;
&lt;li&gt;statements don&#x27;t return a value, expressions evaluate to a return&lt;&#x2F;li&gt;
&lt;li&gt;expressions do not include ending semicolons, then they become a statement&lt;&#x2F;li&gt;
&lt;li&gt;last expression is an implicit return, explicit with &lt;code&gt;return&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;return always needs type in function signature&lt;&#x2F;li&gt;
&lt;li&gt;simple &lt;code&gt;if&#x2F;else if&#x2F;else&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;condition must be a &lt;code&gt;bool&lt;&#x2F;code&gt;, truthy&#x2F;falsey like in JavaScript&lt;&#x2F;li&gt;
&lt;li&gt;if is an expression, so we can use it in a &lt;code&gt;let&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;loop&lt;&#x2F;code&gt;: infinitelly until &lt;code&gt;break&lt;&#x2F;code&gt;, return value follows behind&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;while&lt;&#x2F;code&gt;: specific case (instead of loop, if&#x2F;else, break construct)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;for in&lt;&#x2F;code&gt;: mostly used, also with a range&lt;&#x2F;li&gt;
&lt;li&gt;shadowing to hide old vars with the same name&lt;&#x2F;li&gt;
&lt;li&gt;no implicit casting&lt;&#x2F;li&gt;
&lt;li&gt;cast with &lt;code&gt;From&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;Into&lt;&#x2F;code&gt; traits or &lt;code&gt;TryFrom&lt;&#x2F;code&gt;&#x2F;&lt;code&gt;TryInto&lt;&#x2F;code&gt; traits&lt;&#x2F;li&gt;
&lt;li&gt;convert to String by implementing &lt;code&gt;Display&lt;&#x2F;code&gt; and using &lt;code&gt;to_string&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;parse a String by using &lt;code&gt;parse&lt;&#x2F;code&gt; or turbofish&lt;&#x2F;li&gt;
&lt;li&gt;Filesystem: create, open, remove_file, read_lines, create_dir, remove_dir, read_dir&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;ownership&quot;&gt;Ownership&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;stack faster than heap&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;stack always fixed size, so data with unknown size at compile time or dynamic go to the heap&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;stack and heap both available to the code at runtime&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;stack stores values in the order it gets them and removes them in the opposite order (LIFO)&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;heap gives you a certain amount of space by a pointer (&amp;quot;allocating on the heap&amp;quot;), but free memory has to get searched for&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;the pointer is fixed size, so it can go on the stack&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;for the data, you have to follow the pointer&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;pushing to the stack is faster than allocating to the heap, because no need to search for free space&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;accessing the stack is faster, because you have to follow the pointer if you use the heap&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;normally garbage collector or manual freeing, Rust uses ownership&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;to make memory safety guarantees without a garbage collector&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;borrow, slices, data in memory&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;the compiler checks set rules at compile time&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;each value has a variable called its &lt;em&gt;owner&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;there can only be one owner at a time&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;when the owner goes out of scope, the value gets dropped&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;second &lt;code&gt;String&lt;&#x2F;code&gt; type, &lt;code&gt;from&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;string literal is immutable, so hardcoded into the binary, so fast&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;String is mutable, so unknown size at compile time, so lives on the heap&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;we need a way of returning this memory when we are done with the String&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;without a garbage collector, we have to do it; too late, we waste memory; too early, we have an invalid variable&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;drop&lt;&#x2F;code&gt; gets called at the closing curly bracket&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;ownership manages heap data&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;with simple values, we copy the data onto the stack&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;with a string, we make a copy of the memory address, both point to the same data on the heap&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;a copy of the data could be very expensive&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;double free error: if heap would get dropped, but two pointers referred to one heap address&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;shallow copy becomes a &lt;code&gt;move&lt;&#x2F;code&gt;: s1 was moved into s2, so no double free error =&amp;gt; use &lt;code&gt;clone&lt;&#x2F;code&gt; to deep copy&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;with fixed values no need for &lt;code&gt;clone&lt;&#x2F;code&gt;, because everything just lives on the stack&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;data on the stack (fixed size) has a &lt;code&gt;Copy&lt;&#x2F;code&gt; trait, so an older variable is still usable after assignment&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;reference (&lt;code&gt;&amp;amp;&lt;&#x2F;code&gt;): if you want to use it again, in addition to any data returned from function&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;reference: because it does not own it, the value will not get dropped when reference goes out of scope&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;having references = function parameters borrowing&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;to modify borrowed: because references are immutable, we have to make it mutable&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;only one mutable reference per scope allowed =&amp;gt; prevents data races at compile time&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;not allowed to combine mutable and immutable references&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;data race occurs: two pointers access the same data the same time, one writes, so no sync&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;dangling reference: data goes out of scope, but reference exists&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;slices: if data with context loses context, e.g. index of string, but string gets deleted&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;string slice: &lt;code&gt;&amp;amp;s[a..b]&lt;&#x2F;code&gt;; starting point and lenght get stored&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;string literals are string slices, type &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;other slices for array etc.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;vec0&lt;&#x2F;code&gt; is being &lt;em&gt;moved&lt;&#x2F;em&gt; into the function &lt;code&gt;fill_vec&lt;&#x2F;code&gt; (line 6), so it gets dropped at the end of &lt;code&gt;fill_vec&lt;&#x2F;code&gt;, so we can&#x27;t use &lt;code&gt;vec0&lt;&#x2F;code&gt; again back in &lt;code&gt;main&lt;&#x2F;code&gt; after the &lt;code&gt;fill_vec&lt;&#x2F;code&gt; call&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;we can fix this in a few ways:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Make a separate version of the data in &lt;code&gt;vec0&lt;&#x2F;code&gt; and pass that to &lt;code&gt;fill_vec&lt;&#x2F;code&gt; instead&lt;&#x2F;li&gt;
&lt;li&gt;Make &lt;code&gt;fill_vec&lt;&#x2F;code&gt; borrow its argument instead of taking ownership of it and then copy the data within the function in order to return an owned &lt;code&gt;Vec&amp;lt;i32&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Make &lt;code&gt;fill_vec&lt;&#x2F;code&gt; &lt;em&gt;mutably&lt;&#x2F;em&gt; borrow its argument (which will need to be mutable), modify it directly, then not return anything. Then you can get rid of &lt;code&gt;vec1&lt;&#x2F;code&gt; entirely&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;structs&quot;&gt;Structs&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;custom data type to name and package related values =&amp;gt; does the data belong together?&lt;&#x2F;li&gt;
&lt;li&gt;looks like JavaScript object &lt;code&gt;{}&lt;&#x2F;code&gt; with key-value pairs&lt;&#x2F;li&gt;
&lt;li&gt;add struct methods with &lt;code&gt;impl&lt;&#x2F;code&gt; block, and borrow &lt;code&gt;self&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;associated function: does not use self, e.g. for constructors&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;enums-and-pattern-matching&quot;&gt;Enums and Pattern Matching&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;enum for predefined options&lt;&#x2F;li&gt;
&lt;li&gt;no &lt;code&gt;null&lt;&#x2F;code&gt; values&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;, either &lt;code&gt;Some(T)&lt;&#x2F;code&gt; or &lt;code&gt;None&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; and &lt;code&gt;T&lt;&#x2F;code&gt; are different types, so we can&#x27;t handle &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; like a definitely &lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;this helps to handle one very common problem: handling null as if it would not be null&lt;&#x2F;li&gt;
&lt;li&gt;everywhere that a value has a type that isn’t an &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;, you can safely assume that the value isn’t null.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;match&lt;&#x2F;code&gt; is like &lt;code&gt;switch&lt;&#x2F;code&gt; in JS&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;match&lt;&#x2F;code&gt; is exhaustive, so every case must get handled&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;_&lt;&#x2F;code&gt; to handle all other cases&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;if let&lt;&#x2F;code&gt; if we only care about one case&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;managing-projects&quot;&gt;Managing Projects&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;crate: a binary or library&lt;&#x2F;li&gt;
&lt;li&gt;package: one or more crates; contains a &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; that describes how to build those crates&lt;&#x2F;li&gt;
&lt;li&gt;a package must contain 0 or 1 library crate and multiple binary crates, but at least 1 crate&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;src&#x2F;main.rs&lt;&#x2F;code&gt; is the crate root of a binary crate&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;src&#x2F;lib.rs&lt;&#x2F;code&gt; is the crate root of a library crate&lt;&#x2F;li&gt;
&lt;li&gt;other binary crate go into &lt;code&gt;src&#x2F;bin&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;use&lt;&#x2F;code&gt; brings a path into scope&lt;&#x2F;li&gt;
&lt;li&gt;module: to organize code within a create&lt;&#x2F;li&gt;
&lt;li&gt;all items in inner scopes are private by default&lt;&#x2F;li&gt;
&lt;li&gt;idiomatic way is to bring parent in scope to know that it comes from the outside&lt;&#x2F;li&gt;
&lt;li&gt;add external packages: add to &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt; and import it with &lt;code&gt;use&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;standard library is shipped with Rust, but has to get imported too&lt;&#x2F;li&gt;
&lt;li&gt;import all functions with &lt;code&gt;*&lt;&#x2F;code&gt;, but be cautious!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;common-collections&quot;&gt;Common Collections&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;collections can contain multiple values&lt;&#x2F;li&gt;
&lt;li&gt;always live on the heap, so they are dynamically-sized (size not known at compile-time unlike array and tuple)&lt;&#x2F;li&gt;
&lt;li&gt;vector:
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;vec&#x2F;struct.Vec.html&quot;&gt;Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;a variable number of values next to each other&lt;&#x2F;li&gt;
&lt;li&gt;all values of same type&lt;&#x2F;li&gt;
&lt;li&gt;Create: &lt;code&gt;Vec::new()&lt;&#x2F;code&gt; or &lt;code&gt;vec![]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Read: &lt;code&gt;get&lt;&#x2F;code&gt;, &lt;code&gt;[]&lt;&#x2F;code&gt; (panics)&lt;&#x2F;li&gt;
&lt;li&gt;Update: &lt;code&gt;push&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;no mutable borrow: mutable data could lead to new memory location of borrow&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;for i in &amp;amp;v&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;dereference with &lt;code&gt;*&lt;&#x2F;code&gt; to mutate mutable reference&lt;&#x2F;li&gt;
&lt;li&gt;use enum to store different types in vector&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;string:
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;string&#x2F;struct.String.html&quot;&gt;Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;a collection of characters &#x2F; bytes of text&lt;&#x2F;li&gt;
&lt;li&gt;2 types: &lt;code&gt;str&lt;&#x2F;code&gt; and &lt;code&gt;String&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;str&lt;&#x2F;code&gt;: dynamically sized, string slice, borrowed as &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;, simple, fast, pointer &lt;code&gt;&amp;amp;&lt;&#x2F;code&gt; goes to stack, data to heap&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;String&lt;&#x2F;code&gt;: dynamically sized, mutable, owned, UTF-8, slower, a pointer to the heap, owned&lt;&#x2F;li&gt;
&lt;li&gt;string literal is a &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;String&lt;&#x2F;code&gt; is &lt;code&gt;Vec&amp;lt;u8&amp;gt;&lt;&#x2F;code&gt; under the hood&lt;&#x2F;li&gt;
&lt;li&gt;UTF-8 uses either bytes, scalars or grapheme clusters (mostly what we think is a &amp;quot;character&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;to read grapheme clusters, use an external crate&lt;&#x2F;li&gt;
&lt;li&gt;Create: &lt;code&gt;String::new()&lt;&#x2F;code&gt; or &lt;code&gt;String::from(&amp;quot;&amp;quot;)&lt;&#x2F;code&gt; or &lt;code&gt;&amp;quot;&amp;quot;.to_string()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Read: &lt;code&gt;for c in &amp;quot;&amp;quot;.chars()&lt;&#x2F;code&gt;, but not indexable (due UTF-8, return type issues, expected O(1))&lt;&#x2F;li&gt;
&lt;li&gt;Update: &lt;code&gt;push_str&lt;&#x2F;code&gt;, &lt;code&gt;s1 + &amp;amp;s2&lt;&#x2F;code&gt; (takes ownership of s1, appends copy of s2 and returns ownership of result&lt;code&gt;), &lt;&#x2F;code&gt;format!` for multiple strings&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;hashmap:
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;std&#x2F;collections&#x2F;struct.HashMap.html&quot;&gt;Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;key-value pairs&lt;&#x2F;li&gt;
&lt;li&gt;names in other languages: map, object, hash table, dictionary&lt;&#x2F;li&gt;
&lt;li&gt;to look up by key instead of index as in vector&lt;&#x2F;li&gt;
&lt;li&gt;types with &lt;code&gt;Copy&lt;&#x2F;code&gt; trait and owned values will be moved into and owned by the hashmap&lt;&#x2F;li&gt;
&lt;li&gt;Create: &lt;code&gt;HashMap::new()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Read: &lt;code&gt;get&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Update: &lt;code&gt;insert&lt;&#x2F;code&gt; (overwrite), &lt;code&gt;entry.or_insert&lt;&#x2F;code&gt; (only if not existing)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;error-handling&quot;&gt;Error Handling&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;error handling before code will compile&lt;&#x2F;li&gt;
&lt;li&gt;2 types: unrecoverable (bug?!) and recoverable (retry)&lt;&#x2F;li&gt;
&lt;li&gt;no exceptions, but &lt;code&gt;panic!&lt;&#x2F;code&gt; and &lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;unrecoverable:
&lt;ul&gt;
&lt;li&gt;bad things can happen, so show failure message, clean up and quit&lt;&#x2F;li&gt;
&lt;li&gt;use backtrace for further debugging&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;recoverable:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt; as result&lt;&#x2F;li&gt;
&lt;li&gt;use (nested) &lt;code&gt;match&lt;&#x2F;code&gt; with &lt;code&gt;Ok&lt;&#x2F;code&gt; and &lt;code&gt;Err&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;more advanced: &lt;code&gt;unwrap&lt;&#x2F;code&gt; or &lt;code&gt;expect&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;propagation with &lt;code&gt;?&lt;&#x2F;code&gt; for functions that return &lt;code&gt;Result&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;returning &lt;code&gt;Result&lt;&#x2F;code&gt; as a good default choice&lt;&#x2F;li&gt;
&lt;li&gt;panic if code could end up in bad state (broken contract, not expected)&lt;&#x2F;li&gt;
&lt;li&gt;create own type to add checks, e.g. if number is between 1 and 100&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;unwrap&lt;&#x2F;code&gt; internally calls a panic with no error message =&amp;gt; quick and dirty, we get the value or a stop&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;expect&lt;&#x2F;code&gt; is slightly nicer, with a custom message&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;?&lt;&#x2F;code&gt; propagates the error up, with no crash&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;match&lt;&#x2F;code&gt; is best practice&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;generic-types-traits-and-lifetimes&quot;&gt;Generic Types, Traits, and Lifetimes&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;abstract stand-ins for concrete types or other properties&lt;&#x2F;li&gt;
&lt;li&gt;to express behavior or relation to other things without knowing what will be in their place&lt;&#x2F;li&gt;
&lt;li&gt;e.g. find the largest item in a slice of i32 values and find the largest item in a slice if char values&lt;&#x2F;li&gt;
&lt;li&gt;to parameterize the type in a function, we need to name the type parameter, so we use &lt;code&gt;T&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;fn largest&amp;lt;T&amp;gt;(list: &amp;amp;[T]) -&amp;gt; T {&lt;&#x2F;code&gt; =&amp;gt; &amp;quot;the function &lt;code&gt;largest&lt;&#x2F;code&gt; is generic over some type &lt;code&gt;T&lt;&#x2F;code&gt; and has one parameter named &lt;code&gt;list&lt;&#x2F;code&gt;, which is a slice of values of type &lt;code&gt;T&lt;&#x2F;code&gt; and returns a value of the same type &lt;code&gt;T&lt;&#x2F;code&gt;&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;same goes for structs: &lt;code&gt;struct Point&amp;lt;T, U&amp;gt; { x: T, y: U }&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;and enums: &lt;code&gt;enum Result&amp;lt;T, E&amp;gt; { Ok(T), Err(E), }&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;and impl: &lt;code&gt;impl&amp;lt;T&amp;gt; Point&amp;lt;T&amp;gt; {&lt;&#x2F;code&gt;, but &lt;code&gt;impl Point&amp;lt;i32&amp;gt; {&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Rust implements generics so that the code is not slower&lt;&#x2F;li&gt;
&lt;li&gt;monomorphization: turning generic code into specific code by filling the concrete types&lt;&#x2F;li&gt;
&lt;li&gt;e.g. &lt;code&gt;Option&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; becomes &lt;code&gt;Option_i32&lt;&#x2F;code&gt; and &lt;code&gt;Option_f64&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;trait:
&lt;ul&gt;
&lt;li&gt;functionality a particular type has and can share with other types&lt;&#x2F;li&gt;
&lt;li&gt;similar to interfaces&lt;&#x2F;li&gt;
&lt;li&gt;e.g. we have a &lt;code&gt;news&lt;&#x2F;code&gt; struct and a &lt;code&gt;tweet&lt;&#x2F;code&gt; struct and both need a &lt;code&gt;Summary&lt;&#x2F;code&gt; trait; we can setup a default implementation and override it in each struct&lt;&#x2F;li&gt;
&lt;li&gt;we can use &lt;code&gt;impl Trait&lt;&#x2F;code&gt; or Trait bound syntax&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;lifetime:
&lt;ul&gt;
&lt;li&gt;rust&#x27;s most distinctive feature&lt;&#x2F;li&gt;
&lt;li&gt;every reference has a lifetime, mostly implicit and inferred&lt;&#x2F;li&gt;
&lt;li&gt;goal is to prevent dangling references&lt;&#x2F;li&gt;
&lt;li&gt;borrow checker to check if all borrows are valid&lt;&#x2F;li&gt;
&lt;li&gt;each function that uses references need to specify lifetimes&lt;&#x2F;li&gt;
&lt;li&gt;lifetime annotations describe the relationship of the lifetimes to each other w&#x2F;o affecting the lifetime&lt;&#x2F;li&gt;
&lt;li&gt;e.g. &lt;code&gt;&amp;amp;&#x27;a i32&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;struct definitions can also hold lifetime annotations&lt;&#x2F;li&gt;
&lt;li&gt;lifetime elision rules: 1 input lifetime rule (parameters), 2 output lifetime rules (returns)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;static&lt;&#x2F;code&gt; for lifetime as long as the whole program&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;writing-automated-tests&quot;&gt;Writing Automated Tests&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Rust thinks in unit tests (small, isolated) and integration tests (big, working together)&lt;&#x2F;li&gt;
&lt;li&gt;Rust high amount of concern about correctness&lt;&#x2F;li&gt;
&lt;li&gt;type system big part, but can&#x27;t catch every kind of incorrectness&lt;&#x2F;li&gt;
&lt;li&gt;testing to test for logical (note: find better term) errors&lt;&#x2F;li&gt;
&lt;li&gt;3 steps:
&lt;ul&gt;
&lt;li&gt;
&lt;ol&gt;
&lt;li&gt;arrange: setup data&#x2F;state&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;act: run the code to test&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;assert: check if the results are what you expect&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;terms: &lt;code&gt;cargo run&lt;&#x2F;code&gt;, &lt;code&gt;#[test]&lt;&#x2F;code&gt;, &lt;code&gt;assert_eq!&lt;&#x2F;code&gt;, &lt;code&gt;#[should_panic]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;compared values need &lt;code&gt;PartialEq&lt;&#x2F;code&gt; and &lt;code&gt;Debug&lt;&#x2F;code&gt; traits&lt;&#x2F;li&gt;
&lt;li&gt;custom messages as optional argument&lt;&#x2F;li&gt;
&lt;li&gt;also able to test for panic, but sometimes imprecise due different panics&lt;&#x2F;li&gt;
&lt;li&gt;also use &lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;tests run in parallel (= fast), so they shouldn&#x27;t depend on each other, don&#x27;t have shared state etc.&lt;&#x2F;li&gt;
&lt;li&gt;we can filter tests, e.g. by function name or module name, and also ignore tests&lt;&#x2F;li&gt;
&lt;li&gt;unit tests test for private implementatiosn details, go into each file they are testing, in a &lt;code&gt;tests&lt;&#x2F;code&gt; module with &lt;code&gt;cfg(test)&lt;&#x2F;code&gt; annotation&lt;&#x2F;li&gt;
&lt;li&gt;integration tests test mainly for public API, go into &lt;code&gt;tests&lt;&#x2F;code&gt; directory, each file is a separate crate&lt;&#x2F;li&gt;
&lt;li&gt;setups for integration tests go into a subdirectory of &lt;code&gt;tests&lt;&#x2F;code&gt;, e.g. &lt;code&gt;tests&#x2F;common&#x2F;mod.rs&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;an-i-o-project-building-a-command-line-program&quot;&gt;An I&#x2F;O Project: Building a Command Line Program&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;we build a cli application, our own implementation of grep&lt;&#x2F;li&gt;
&lt;li&gt;we use newly learned knowledge from chapter 7, 8, 9, 10, 11&lt;&#x2F;li&gt;
&lt;li&gt;create new cratewe use newly learned&lt;&#x2F;li&gt;
&lt;li&gt;use &lt;code&gt;std::env&lt;&#x2F;code&gt; to read from environment&lt;&#x2F;li&gt;
&lt;li&gt;use &lt;code&gt;collect&lt;&#x2F;code&gt; to collect iterator &lt;code&gt;args&lt;&#x2F;code&gt; in &lt;code&gt;vec&amp;lt;String&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;use &lt;code&gt;std::fs&lt;&#x2F;code&gt; to read the file&lt;&#x2F;li&gt;
&lt;li&gt;problems: &lt;code&gt;main&lt;&#x2F;code&gt; parses cli args and reads file, different kind of tasks for vars, bad error message&lt;&#x2F;li&gt;
&lt;li&gt;separation of concerns: split program into &lt;code&gt;main.rs&lt;&#x2F;code&gt; (run program) and &lt;code&gt;lib.rs&lt;&#x2F;code&gt; (program logic)&lt;&#x2F;li&gt;
&lt;li&gt;concerns for &lt;code&gt;main.rs&lt;&#x2F;code&gt;: call cli parsing, set up config, call &lt;code&gt;run&lt;&#x2F;code&gt; in &lt;code&gt;lib.rs&lt;&#x2F;code&gt;, handle errors&lt;&#x2F;li&gt;
&lt;li&gt;cli parsing: own helper function, move args into correct data structure&lt;&#x2F;li&gt;
&lt;li&gt;Rustaceans normally avoid using &lt;code&gt;clone&lt;&#x2F;code&gt; to fix ownership problems, because of its runtime cost; but there are some pros and cons to it&lt;&#x2F;li&gt;
&lt;li&gt;relate specific functions to struct, e.g. &lt;code&gt;parse_config&lt;&#x2F;code&gt; can become the &lt;code&gt;new&lt;&#x2F;code&gt; function of &lt;code&gt;Config&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;add error handling by returning &lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;extract logic from &lt;code&gt;main&lt;&#x2F;code&gt; into &lt;code&gt;run&lt;&#x2F;code&gt; function&lt;&#x2F;li&gt;
&lt;li&gt;return &lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt; and pass up error with &lt;code&gt;?&lt;&#x2F;code&gt;, then use &lt;code&gt;if let&lt;&#x2F;code&gt; to check for error&lt;&#x2F;li&gt;
&lt;li&gt;move logic into &lt;code&gt;lib.rs&lt;&#x2F;code&gt; and import &lt;code&gt;Config&lt;&#x2F;code&gt; and prefix &lt;code&gt;run&lt;&#x2F;code&gt; with &lt;code&gt;minigrep::&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;use TDD to implement search functionality to keep test coverage high&lt;&#x2F;li&gt;
&lt;li&gt;enviornment variables, e.g. if env var is on, then ignore casing&lt;&#x2F;li&gt;
&lt;li&gt;write errors to sterr instead of stdout by sending errors to file, so errors also show up in stdout&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;functional-language-features-iterators-and-closures&quot;&gt;Functional Language Features: Iterators and Closures&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;significantly influenced by functional programming&lt;&#x2F;li&gt;
&lt;li&gt;a way to clearly express highlevel ideas at low-level performance&lt;&#x2F;li&gt;
&lt;li&gt;closures:
&lt;ul&gt;
&lt;li&gt;anonymous functions saved in a variable or passed as arguments&lt;&#x2F;li&gt;
&lt;li&gt;can capture values from the scope in which they are defined&lt;&#x2F;li&gt;
&lt;li&gt;refactoring of &lt;code&gt;expensive_calculation&lt;&#x2F;code&gt; into a closure that holds the function (NOT the result)&lt;&#x2F;li&gt;
&lt;li&gt;no need for type annotations, because no exposed interface: &lt;code&gt;let add_one_v4 = |x| x + 1;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;solution: create struct with closure and result, use memoization to store result and run only when needed, also use hashmap, so that we can override struct value&lt;&#x2F;li&gt;
&lt;li&gt;closures can capture their environment, function can not (scoped by curly brackets)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Fn&lt;&#x2F;code&gt;: borrows immutably, &lt;code&gt;FnMut&lt;&#x2F;code&gt;: borrows mutably, &lt;code&gt;FnOnce&lt;&#x2F;code&gt;: takes ownership once&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;iterators:
&lt;ul&gt;
&lt;li&gt;perform tasks on a sequence of items&lt;&#x2F;li&gt;
&lt;li&gt;iterators are lazy, so they don&#x27;t run until you call them&lt;&#x2F;li&gt;
&lt;li&gt;without iterators, you would e.g. use a normal for loop with index&lt;&#x2F;li&gt;
&lt;li&gt;all iterators implement the &lt;code&gt;Iterator&lt;&#x2F;code&gt; trait: needs &lt;code&gt;Item&lt;&#x2F;code&gt; type and &lt;code&gt;next&lt;&#x2F;code&gt; function&lt;&#x2F;li&gt;
&lt;li&gt;iterator is mutable by design and consumes itself, the for loop takes ownership&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;iter&lt;&#x2F;code&gt; produces immutable references&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;iter_mut&lt;&#x2F;code&gt; produces mutable references&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;into_iter&lt;&#x2F;code&gt; produces owned values&lt;&#x2F;li&gt;
&lt;li&gt;e.g. &lt;code&gt;sum&lt;&#x2F;code&gt; takes ownership, calls &lt;code&gt;next&lt;&#x2F;code&gt;, consumes the iterator&lt;&#x2F;li&gt;
&lt;li&gt;other methods in the &lt;code&gt;Iterator&lt;&#x2F;code&gt; trait are called iterator adapters and we can chain them&lt;&#x2F;li&gt;
&lt;li&gt;because iterators are lazy, we have to call one consuming adaptor, e.g. &lt;code&gt;collect&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;we can implement the &lt;code&gt;Iterator&lt;&#x2F;code&gt; trait on our own data structures&lt;&#x2F;li&gt;
&lt;li&gt;iterators (higher level) equally as fast as for loop (lower level) due zero-cost abstraction, because they get compiled down to roughly the same code&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;find&lt;&#x2F;code&gt; to find value and &lt;code&gt;position&lt;&#x2F;code&gt; for index&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;more-about-cargo-and-crates-io&quot;&gt;More about Cargo and Crates.io&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;release profiles are predefined prfiles with different configs&lt;&#x2F;li&gt;
&lt;li&gt;cargo has two default profiles: dev and release&lt;&#x2F;li&gt;
&lt;li&gt;control it in &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;crates.io to use other peoples code and publish your own code&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;&lt;&#x2F;code&gt; for code comments, &lt;code&gt;&#x2F;&#x2F;&#x2F;&lt;&#x2F;code&gt; for documentation commentsi, &lt;code&gt;&#x2F;&#x2F;!&lt;&#x2F;code&gt; for crate comments&lt;&#x2F;li&gt;
&lt;li&gt;documentation comments can include tests, runnable with &lt;code&gt;cargo test&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;pub use&lt;&#x2F;code&gt; to re-export types at the top level for more useful public API structure&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;cargo doc&lt;&#x2F;code&gt; to build documentation&lt;&#x2F;li&gt;
&lt;li&gt;metadata for crate goes into &lt;code&gt;Cargo.toml&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;workspace as a set of packages&lt;&#x2F;li&gt;
&lt;li&gt;all crates in the workspace will use the same dependencies to be compatible with each other&lt;&#x2F;li&gt;
&lt;li&gt;Regular comments which are ignored by the compiler:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&#x2F;&#x2F; Line comments which go to the end of the line.&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&#x2F;* Block comments which go to the closing delimiter. *&#x2F;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Doc comments which are parsed into HTML library documentation:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;&#x2F; Generate library docs for the following item.&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;&#x2F;&#x2F;! Generate library docs for the enclosing item.&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;smart-pointers&quot;&gt;Smart Pointers&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;a pointer is a concept for a variable that contains an address in memory&lt;&#x2F;li&gt;
&lt;li&gt;Rust&#x27;s most common kind of pointer is a reference, that always borrows data&lt;&#x2F;li&gt;
&lt;li&gt;a smart pointer is a data structure that acts like a pointer but also has metadata and extra capabilities&lt;&#x2F;li&gt;
&lt;li&gt;e.g. the reference counting smart pointer to have multiple owners of data&lt;&#x2F;li&gt;
&lt;li&gt;smart pointers can own data, in contrast to a normal reference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;String&lt;&#x2F;code&gt; and &lt;code&gt;Vec&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; are smart pointers&lt;&#x2F;li&gt;
&lt;li&gt;smart pointers are usually implemented using structs&lt;&#x2F;li&gt;
&lt;li&gt;they implement the &lt;code&gt;Deref&lt;&#x2F;code&gt; and &lt;code&gt;Drop&lt;&#x2F;code&gt; trait&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Deref&lt;&#x2F;code&gt; to act like a reference, &lt;code&gt;Drop&lt;&#x2F;code&gt; to customize the code that is run when the instance goes out of scope&lt;&#x2F;li&gt;
&lt;li&gt;most used smart pointers: &lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;, &lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;, &lt;code&gt;Ref&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;:
&lt;ul&gt;
&lt;li&gt;allows to store data on the heap instead of the stack, stack only has the pointer to the heap data&lt;&#x2F;li&gt;
&lt;li&gt;no performance overhead&lt;&#x2F;li&gt;
&lt;li&gt;usage: when you have a type whose size can&#x27;t be known at compile time; when you want to transfer ownership without copying; when you want to own a value and care only that it is a type that implement a specific trait&lt;&#x2F;li&gt;
&lt;li&gt;enabling recursive types with boxes, where a value can have as part of itself another value of the same type; this could be infinitely, so Rust doesn&#x27;t know how much space a value needs, e.g. in a &lt;code&gt;Cons List&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;the list has an element and itself; by using a &lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; with a pointer, the next cons list element is always the same size and we&#x27;ve broken the infinite, recursive chain&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;:
&lt;ul&gt;
&lt;li&gt;sometimes a value might have multiple owners, e.g. a node in a graph&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;rc&lt;&#x2F;code&gt; stands for &lt;code&gt;reference counting&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;keeps track of the number of references&lt;&#x2F;li&gt;
&lt;li&gt;via immutable references it allows to share data between multiple parts of the program for reading only&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;RefCell&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;:
&lt;ul&gt;
&lt;li&gt;a design pattern to mutate data even when there are immutable references to that data&lt;&#x2F;li&gt;
&lt;li&gt;difference to &lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt;: borrowing rules are enforced at runtime instead of compile time&lt;&#x2F;li&gt;
&lt;li&gt;combination of &lt;code&gt;RefCell&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; and &lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; to have data with multiple owners and mutate it&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Deref:
&lt;ul&gt;
&lt;li&gt;allows to customize the behavior of &lt;code&gt;\*&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;we can&#x27;t compare a value and a reference to a value because of different types, so we have to dereference&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;\*y&lt;&#x2F;code&gt; actually means &lt;code&gt;\*(y.deref())&lt;&#x2F;code&gt;, so we don&#x27;t have to know if it is a regular reference or a type that implements &lt;code&gt;Deref&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;deref&lt;&#x2F;code&gt; returns a reference, otherwise the value would be moved out of &lt;code&gt;self&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;deref coercion happens when we pass a reference to a type&#x27;s value as an argument to a function that does not match the parameter type, e.g. from &lt;code&gt;&amp;amp;String&lt;&#x2F;code&gt; to &lt;code&gt;&amp;amp;str&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;to override the &lt;code&gt;\*&lt;&#x2F;code&gt; operator on mutable references, we use &lt;code&gt;DerefMut&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Drop:
&lt;ul&gt;
&lt;li&gt;allows to customize what happens when a value goes out of scope, e.g. &lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; deallocates the heap space&lt;&#x2F;li&gt;
&lt;li&gt;variables are dropped in reverse order of their creation&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;std::mem::drop&lt;&#x2F;code&gt; to drop a value (own explicit &lt;code&gt;drop&lt;&#x2F;code&gt; would lead to double free error)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;reference cycles can leak memory (which are memory safe)&lt;&#x2F;li&gt;
&lt;li&gt;Summary:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; enables multiple owners&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Box&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; allows immutable or mutable borrows checked at compile time, &lt;code&gt;Rc&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; allows only immutable borrows checked at compile time, &lt;code&gt;RefCell&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; allows immutable or mutable borrows checked at runtime&lt;&#x2F;li&gt;
&lt;li&gt;you can mutate the value inside &lt;code&gt;RefCell&amp;lt;T&amp;gt;&lt;&#x2F;code&gt; even when it is immutable&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;fearless-concurrency&quot;&gt;Fearless Concurrency&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;concurrent programming: different parts of a program execute independently&lt;&#x2F;li&gt;
&lt;li&gt;parallel programming: different parts of a program execute at the same time&lt;&#x2F;li&gt;
&lt;li&gt;by leveraging ownership and type checking, many concurrency errors are compile-time errors in Rust&lt;&#x2F;li&gt;
&lt;li&gt;OS run program&#x27;s in a process and the OS manages multiple processes at once&lt;&#x2F;li&gt;
&lt;li&gt;programs can run independent parts simultaneously by using threads&lt;&#x2F;li&gt;
&lt;li&gt;splitting the computation can improve performance and increase complexity&lt;&#x2F;li&gt;
&lt;li&gt;possible problems:
&lt;ul&gt;
&lt;li&gt;race conditions: inconsistent order of accessing reources&lt;&#x2F;li&gt;
&lt;li&gt;deadlock: multiple threads wait for each other to finish using a resource, preventing each other from continuing&lt;&#x2F;li&gt;
&lt;li&gt;bugs that happen only in specific situations, that are hard to debug&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Rust uses 1:1 threading, where it calls the OS API to create threads in a 1:1 manner, to have a smaller language runtime&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;thread::spawn&lt;&#x2F;code&gt; to create a new thread&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;move&lt;&#x2F;code&gt; allows us to use data from one thread in another one&lt;&#x2F;li&gt;
&lt;li&gt;option 1: message passing:
&lt;ul&gt;
&lt;li&gt;to transfer data between threads by using channels&lt;&#x2F;li&gt;
&lt;li&gt;a channel has a transmitter and a receiver&lt;&#x2F;li&gt;
&lt;li&gt;multiple producers, single consumer&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;option 2: shared-state concurrenty:
&lt;ul&gt;
&lt;li&gt;uses mutex&lt;&#x2F;li&gt;
&lt;li&gt;only one thread allowed to access some data at any given time&lt;&#x2F;li&gt;
&lt;li&gt;uses locks&lt;&#x2F;li&gt;
&lt;li&gt;like managing the microphone on a panel discussion&lt;&#x2F;li&gt;
&lt;li&gt;`Arc&lt;T&gt;: atomic Rc that is safe to share across threads&lt;&#x2F;li&gt;
&lt;li&gt;allow transference of ownership between threads with &lt;code&gt;Send&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;allow access from multiple threads with &lt;code&gt;Sync&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;object-oriented-programming-features-of-rust&quot;&gt;Object Oriented Programming Features of Rust&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;structs and enums have data, &lt;code&gt;impl&lt;&#x2F;code&gt; provides methods on them&lt;&#x2F;li&gt;
&lt;li&gt;encapsulation by using &lt;code&gt;pub&lt;&#x2F;code&gt; and everything else is by default private&lt;&#x2F;li&gt;
&lt;li&gt;Rust has no inheritance, but traits to share code&lt;&#x2F;li&gt;
&lt;li&gt;Rust uses generics to abstract over different possible types and trait bounds (bounded parametric polymorphism)&lt;&#x2F;li&gt;
&lt;li&gt;use trait objects that allow for values of different types&lt;&#x2F;li&gt;
&lt;li&gt;by using trait objects we never have to check whether a value implements a specific method, because the compiler does this for us&lt;&#x2F;li&gt;
&lt;li&gt;object safety is require for trait objects&lt;&#x2F;li&gt;
&lt;li&gt;we can use the state pattern to encapsulate different kinds of behavior&lt;&#x2F;li&gt;
&lt;li&gt;but OOP patterns won&#x27;t always be the best way to use Rust&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;patterns-and-matching&quot;&gt;Patterns and Matching&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;special syntax for matching against the structure of types&lt;&#x2F;li&gt;
&lt;li&gt;places to use patterns: match (exhaustive), if let (not exhaustive), while let, for, let (!), function parameters&lt;&#x2F;li&gt;
&lt;li&gt;refutable: can fail to match, e.g. &lt;code&gt;Some(x)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;irrefutable: match for any possible value, e.g. &lt;code&gt;let x = 1;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;function parameters, let and for can only accept irrefutable patterns&lt;&#x2F;li&gt;
&lt;li&gt;matching literals&lt;&#x2F;li&gt;
&lt;li&gt;matching named variables&lt;&#x2F;li&gt;
&lt;li&gt;multiple patterns with &lt;code&gt;|&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;matching ranges with &lt;code&gt;..=&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;destructuring to break apart values&lt;&#x2F;li&gt;
&lt;li&gt;ignoring values with &lt;code&gt;_&lt;&#x2F;code&gt; (no binding), &lt;code&gt;_x&lt;&#x2F;code&gt; (with binding), &lt;code&gt;..&lt;&#x2F;code&gt; (multiple values)&lt;&#x2F;li&gt;
&lt;li&gt;match guards with if in arm&lt;&#x2F;li&gt;
&lt;li&gt;@ bindings&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;advanced-features&quot;&gt;Advanced Features&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;unsafe Rust:
&lt;ul&gt;
&lt;li&gt;underlying computer hardware is inherently unsafe&lt;&#x2F;li&gt;
&lt;li&gt;unsafe rust: by nature, static analysis is conservative&lt;&#x2F;li&gt;
&lt;li&gt;unsafe does not turn off any safety check (e.g. the borrow checker)&lt;&#x2F;li&gt;
&lt;li&gt;enclose unsafe code within a safe abstraction and provide a safe API&lt;&#x2F;li&gt;
&lt;li&gt;superpowers: dereference a raw pointer, call an unsafe function, access or modify a mutable static variable, implement an unsafe trait, access fields of unions&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;advanced traits:
&lt;ul&gt;
&lt;li&gt;specifying placeholder types in trait definitions&lt;&#x2F;li&gt;
&lt;li&gt;default generic type parameters and operator overloading&lt;&#x2F;li&gt;
&lt;li&gt;fully qualified syntax for disambiguation&lt;&#x2F;li&gt;
&lt;li&gt;using supertraits to require one trait&#x27;s functionality within another trait&lt;&#x2F;li&gt;
&lt;li&gt;using the newtype pattern to implement external trits on external types&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;advanced types:
&lt;ul&gt;
&lt;li&gt;using the newtype pattern for type safety and abstraction&lt;&#x2F;li&gt;
&lt;li&gt;creating type synonyms with types aliases&lt;&#x2F;li&gt;
&lt;li&gt;the never type that never returns&lt;&#x2F;li&gt;
&lt;li&gt;dynamically sized types and the Sized trait&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;advanced functions and closures:
&lt;ul&gt;
&lt;li&gt;function pointers&lt;&#x2F;li&gt;
&lt;li&gt;returning closures&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;macros:
&lt;ul&gt;
&lt;li&gt;basic ones: &lt;code&gt;format!&lt;&#x2F;code&gt;, &lt;code&gt;print!&lt;&#x2F;code&gt;, &lt;code&gt;eprint!&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;macros are code that write other code (metaprogramming)&lt;&#x2F;li&gt;
&lt;li&gt;macros are expanded before the compiler interprets the meaning of the code&lt;&#x2F;li&gt;
&lt;li&gt;custom &lt;code&gt;#[derive]&lt;&#x2F;code&gt; macros used on structs on enums&lt;&#x2F;li&gt;
&lt;li&gt;attribute-like macros define custom attributes usable on any item&lt;&#x2F;li&gt;
&lt;li&gt;function-like macros looking like function calls but operate on the tokens specified as their argument&lt;&#x2F;li&gt;
&lt;li&gt;format!: write formatted text to String&lt;&#x2F;li&gt;
&lt;li&gt;print!: same as format! but the text is printed to the console (io::stdout).&lt;&#x2F;li&gt;
&lt;li&gt;println!: same as print! but a newline is appended.&lt;&#x2F;li&gt;
&lt;li&gt;eprint!: same as format! but the text is printed to the standard error (io::stderr).&lt;&#x2F;li&gt;
&lt;li&gt;eprintln!: same as eprint!but a newline is appended.&lt;&#x2F;li&gt;
&lt;li&gt;todo!: not implemented yet&lt;&#x2F;li&gt;
&lt;li&gt;dbg!: print debug to cli&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;final-project-building-a-multithreaded-web-server&quot;&gt;Final Project: Building a Multithreaded Web Server&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;steps:
&lt;ul&gt;
&lt;li&gt;learn about TCP and HTTP&lt;&#x2F;li&gt;
&lt;li&gt;listen for TCP connections&lt;&#x2F;li&gt;
&lt;li&gt;parse HTTP requests&lt;&#x2F;li&gt;
&lt;li&gt;create a HTTP response&lt;&#x2F;li&gt;
&lt;li&gt;improve server throughput with a thread pool&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;TCP and HTTP:
&lt;ul&gt;
&lt;li&gt;both are request-response protocols (client-server)&lt;&#x2F;li&gt;
&lt;li&gt;TCP: low-level, how information gets from one server to another&lt;&#x2F;li&gt;
&lt;li&gt;HTTP: on top of TCP, defining the contents of request and response&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;listen to requests with &lt;code&gt;TcpListener&lt;&#x2F;code&gt; that binds to an IP&lt;&#x2F;li&gt;
&lt;li&gt;read the request&lt;&#x2F;li&gt;
&lt;li&gt;reply with response&lt;&#x2F;li&gt;
&lt;li&gt;create thread pool to reply to multiple requests&lt;&#x2F;li&gt;
&lt;li&gt;write the client interface first&lt;&#x2F;li&gt;
&lt;li&gt;use channels to communicate between threads&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;appendix&quot;&gt;Appendix&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;derivable traits:
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Debug&lt;&#x2F;code&gt; for programmer output&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;PartialEq&lt;&#x2F;code&gt; and Eq for equality comparisons&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;PartialOrd&lt;&#x2F;code&gt; and Ord for ordering comparisons&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Clone&lt;&#x2F;code&gt; and &lt;code&gt;Copy&lt;&#x2F;code&gt; for duplicating values&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Hash&lt;&#x2F;code&gt; for mapping a value to a value of fixed size&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;Default&lt;&#x2F;code&gt; for default values&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;development tools:
&lt;ul&gt;
&lt;li&gt;formatting: rustfmt&lt;&#x2F;li&gt;
&lt;li&gt;fix code: rustfix&lt;&#x2F;li&gt;
&lt;li&gt;linting: clippy&lt;&#x2F;li&gt;
&lt;li&gt;IDE integration: rust language server&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;other-findings&quot;&gt;Other findings&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;web server frameworks:
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;actix&#x2F;actix-web&quot;&gt;actix&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;SergioBenitez&#x2F;Rocket&quot;&gt;rocket&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;web client frameworks:
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;yewstack&#x2F;yew&quot;&gt;yew&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;iced-rs&#x2F;iced&quot;&gt;iced&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;seed-rs&#x2F;seed&quot;&gt;seed&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;projects-built&quot;&gt;Projects Built&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;cli&quot;&gt;CLI&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;unwrap&lt;&#x2F;code&gt; is equal to &lt;code&gt;match&lt;&#x2F;code&gt; with &lt;code&gt;panic!&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;?&lt;&#x2F;code&gt; is equal to &lt;code&gt;match&lt;&#x2F;code&gt; with &lt;code&gt;return Err()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;anyhow - provides anyhow::Error for easy error handling&lt;&#x2F;li&gt;
&lt;li&gt;assert_cmd - simplifies integration testing of CLIs&lt;&#x2F;li&gt;
&lt;li&gt;atty - detected whether application is running in a tty&lt;&#x2F;li&gt;
&lt;li&gt;clap-verbosity-flag - adds a --verbose flag to structopt CLIs&lt;&#x2F;li&gt;
&lt;li&gt;clap - command line argument parser&lt;&#x2F;li&gt;
&lt;li&gt;confy - boilerplate-free configuration management&lt;&#x2F;li&gt;
&lt;li&gt;convey - easy output for machines and humans&lt;&#x2F;li&gt;
&lt;li&gt;crossbeam-channel - provides multi-producer multi-consumer channels for message passing&lt;&#x2F;li&gt;
&lt;li&gt;ctrlc - easy ctrl-c handler&lt;&#x2F;li&gt;
&lt;li&gt;env_logger - implements a logger configurable via environment variables&lt;&#x2F;li&gt;
&lt;li&gt;exitcode - system exit code constants&lt;&#x2F;li&gt;
&lt;li&gt;human-panic - panic message handler&lt;&#x2F;li&gt;
&lt;li&gt;indicatif - progress bars and spinners&lt;&#x2F;li&gt;
&lt;li&gt;log - provides logging abstracted over implementation&lt;&#x2F;li&gt;
&lt;li&gt;predicates - implements boolean-valued predicate functions&lt;&#x2F;li&gt;
&lt;li&gt;proptest - property testing framework&lt;&#x2F;li&gt;
&lt;li&gt;serde_json - serialize&#x2F;deserialize to JSON&lt;&#x2F;li&gt;
&lt;li&gt;signal-hook - handles UNIX signals&lt;&#x2F;li&gt;
&lt;li&gt;structopt - parses command line arguments into a struct&lt;&#x2F;li&gt;
&lt;li&gt;tokio - asynchronous runtime&lt;&#x2F;li&gt;
&lt;li&gt;wasm-pack - tool for building WebAssembly&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;catsay-cli&quot;&gt;Catsay CLI&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;binaries: single programs tha are used independently&lt;&#x2F;li&gt;
&lt;li&gt;libraries: building blocks for other programs&lt;&#x2F;li&gt;
&lt;li&gt;StructOpt:
&lt;ul&gt;
&lt;li&gt;combines clap (generates a parser for the arguments) and custom derive (generates a default implementation of a trait by annotating a struct)&lt;&#x2F;li&gt;
&lt;li&gt;you can define a struct containing the arguments you want and annotate it with &lt;code&gt;#[derive(StructOpt)]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;publishing:
&lt;ul&gt;
&lt;li&gt;cargo install: installs locally from the source code (rust toolchain needed)&lt;&#x2F;li&gt;
&lt;li&gt;crates.io: higher visibility, but also install from source code&lt;&#x2F;li&gt;
&lt;li&gt;cargo build: builds binary, which you can upload (no rust toolchain needed to run it)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;catsay-tui&quot;&gt;Catsay TUI&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;how to use ncurses and cursive (TUI)&lt;&#x2F;li&gt;
&lt;li&gt;create root, add layers&lt;&#x2F;li&gt;
&lt;li&gt;The event loop is a fundamental concept in building user interfaces.&lt;&#x2F;li&gt;
&lt;li&gt;CLI interactions are usually limited to one input and one output. For user input, you have to pause the execution and wait for the user input to finish. No other operations or output can be processed at that time.&lt;&#x2F;li&gt;
&lt;li&gt;A GUI might be expecting multiple inputs, e.g. keypresses or mouse clicks on a button.&lt;&#x2F;li&gt;
&lt;li&gt;Since you can’t predict which input will be triggered first, the program runs in an infinite loop that handles whatever next input is triggered. If you have registered some event handler, the event loop will
invoke the handler when the event happens. E.g. if you have an OK button in a dialog box, clicking it will trigger a button click event, which might be handled by a handler that closes this dialog box.&lt;&#x2F;li&gt;
&lt;li&gt;Cursive uses layers to create a stacked view of the components (e.g. Views). Layers are stacked together so that the top-most one will be active and can receive input.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;catsay-gui&quot;&gt;Catsay GUI&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;how to use GTK+ (gtk-rs) and Glade&lt;&#x2F;li&gt;
&lt;li&gt;gtk-rs is a rust binding around the C-based GTK library&lt;&#x2F;li&gt;
&lt;li&gt;elements: &lt;code&gt;Application&lt;&#x2F;code&gt;, &lt;code&gt;ApplicationWindow&lt;&#x2F;code&gt;, &lt;code&gt;Box&lt;&#x2F;code&gt;, &lt;code&gt;Label&lt;&#x2F;code&gt;, &lt;code&gt;Image&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;glade to build UI with XML&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;webpage-server-side-rendered&quot;&gt;Webpage Server-Side Rendered&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;actix-web for the http server&lt;&#x2F;li&gt;
&lt;li&gt;the &lt;code&gt;HttpServer&lt;&#x2F;code&gt; serves an &lt;code&gt;App&lt;&#x2F;code&gt; with &lt;code&gt;route&lt;&#x2F;code&gt;s which invoke handlers depending on the request method; the server binds to a specific IP and port and awaits the requests&lt;&#x2F;li&gt;
&lt;li&gt;actix-web uses tokio under the hood&lt;&#x2F;li&gt;
&lt;li&gt;to serve multiple clients, we can create multiple processes (= multiple server instances), but this doesn&#x27;t scale well&lt;&#x2F;li&gt;
&lt;li&gt;we can use multiple threads (parts of a process), but there is also some overhead&lt;&#x2F;li&gt;
&lt;li&gt;with async&#x2F;await, we can serve multiple clients per threads, so it is faster, because it doesn&#x27;t block&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;NamedFile&lt;&#x2F;code&gt; to use a file&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;service&lt;&#x2F;code&gt; e.g. to serve static folder (from actix-files)&lt;&#x2F;li&gt;
&lt;li&gt;handlebars as templating engine, serder_json to use json&lt;&#x2F;li&gt;
&lt;li&gt;diesel as ORM, postgresql as database&lt;&#x2F;li&gt;
&lt;li&gt;schema migration is a way to version-control your database schema (instead of using ad-hoc SQL commands), so you do not miss the ability to quickly roll back or rebuild the database from scratch. When using schema migration, you write a SQL script to apply the schema change and another script to revert the change. You can also bring an old database to the latest schema by applying all the migrations it missed. A migration tool will usually determine which migration needs to be applied, so you don’t have to worry about it&lt;&#x2F;li&gt;
&lt;li&gt;diesel:
&lt;ul&gt;
&lt;li&gt;database table: plural, &lt;code&gt;models.rs&lt;&#x2F;code&gt;: struct singular, &lt;code&gt;schema.rs&lt;&#x2F;code&gt;: autogenerated&lt;&#x2F;li&gt;
&lt;li&gt;order of fields in &lt;code&gt;models&lt;&#x2F;code&gt; should match database table&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;web-api&quot;&gt;Web API&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;actix-web for the http server&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;map_err&lt;&#x2F;code&gt; converts the &lt;code&gt;Err&lt;&#x2F;code&gt; value of a &lt;code&gt;Result&lt;&#x2F;code&gt; from one type to another, leaving the &lt;code&gt;Ok&lt;&#x2F;code&gt; value unchanged, e.g. if we pass a function that converts a value of type E to type F, it will convert &lt;code&gt;Result&amp;lt;T, E&amp;gt;&lt;&#x2F;code&gt; to &lt;code&gt;Result&amp;lt;T, F&amp;gt;&lt;&#x2F;code&gt;; this is useful for passing through the &lt;code&gt;Ok&lt;&#x2F;code&gt; value and handling the &lt;code&gt;Err&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;actix-web errors:
&lt;ul&gt;
&lt;li&gt;ErrorBadRequest(): 400&lt;&#x2F;li&gt;
&lt;li&gt;ErrorNotFound(): 404&lt;&#x2F;li&gt;
&lt;li&gt;ErrorInternalServerError(): 500&lt;&#x2F;li&gt;
&lt;li&gt;ErrorBadGateway(): 502&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;add proper logging: error, warn, info, debug, trace&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;websocket-chat&quot;&gt;WebSocket Chat&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;how can the server start communication, e.g. for notifications?&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;types:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;polling: the client periodically sends a request to the server to see if there are updates; most of the time there aren&#x27;t any updates, so we waste a lot of data&lt;&#x2F;li&gt;
&lt;li&gt;long polling: the server holds the connection open until it has some data, but server now has responsibility of keeping track of open connections&lt;&#x2F;li&gt;
&lt;li&gt;server-sent events: the client connects to the server using the eventsource web api, but this is only unidirectional&lt;&#x2F;li&gt;
&lt;li&gt;websocket: provides bidirectional full-duplex communication over TCP&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;websocket events:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;open: Connection established&lt;&#x2F;li&gt;
&lt;li&gt;message: Received message from the server&lt;&#x2F;li&gt;
&lt;li&gt;error: Error happened&lt;&#x2F;li&gt;
&lt;li&gt;close: Connection closed&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;messages are not simple strings, but frames&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;web-frontend-js-rust&quot;&gt;Web Frontend JS&#x2F;Rust&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;wasm is an open standard for binaries for near-native performance in browsers&lt;&#x2F;li&gt;
&lt;li&gt;we can write rust and compile it to wasm&lt;&#x2F;li&gt;
&lt;li&gt;wasm does not replace javascript&lt;&#x2F;li&gt;
&lt;li&gt;use wasm-pack and wasm-pack-template for the tooling&lt;&#x2F;li&gt;
&lt;li&gt;javascript calls wasm, then wasm does stuff&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;web-frontend-pure-rust&quot;&gt;Web Frontend Pure Rust&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;yew as frontend tool, uses wasm-pack and webpack&lt;&#x2F;li&gt;
&lt;li&gt;yew uses concepts of React and Elm (Model, View, Update&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;from-katas&quot;&gt;From Katas&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;convert to iterator, useful for filter, map: &lt;code&gt;iter&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;check if positive: &lt;code&gt;is_positive&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;math stuff: &lt;code&gt;sum&lt;&#x2F;code&gt;, &lt;code&gt;product&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;range: is between 1 and 3 (inclusive)? &lt;code&gt;1..=3&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;reduce function: &lt;code&gt;fold&lt;&#x2F;code&gt; (takes &lt;code&gt;fold(init, |a, b| fn)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;char in string: &lt;code&gt;chars().nth()&lt;&#x2F;code&gt;, &lt;code&gt;chars().next()&lt;&#x2F;code&gt;, &lt;code&gt;chars().last()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;iterate over string: &lt;code&gt;chars()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;convert a string slice in a given base to an integer: &lt;code&gt;from_str_radix&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;sort and reverse iterator: &lt;code&gt;sort&lt;&#x2F;code&gt;, &lt;code&gt;reverse&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;interesting-topics-questions&quot;&gt;Interesting Topics &#x2F; Questions&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;stack&#x2F;heap&lt;&#x2F;li&gt;
&lt;li&gt;borrows&lt;&#x2F;li&gt;
&lt;li&gt;raw pointer&lt;&#x2F;li&gt;
&lt;li&gt;error handling&lt;&#x2F;li&gt;
&lt;li&gt;is shadowing best practice? duplicate names, harder to debug?&lt;&#x2F;li&gt;
&lt;li&gt;mutable references&lt;&#x2F;li&gt;
&lt;li&gt;structs&lt;&#x2F;li&gt;
&lt;li&gt;traits&lt;&#x2F;li&gt;
&lt;li&gt;lifetime&lt;&#x2F;li&gt;
&lt;li&gt;concurrency&lt;&#x2F;li&gt;
&lt;li&gt;what happens when the used integer is more than my computer architecture, e.g. &lt;code&gt;i128&lt;&#x2F;code&gt; on a 64bit system? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;57340308&#x2F;how-does-rusts-128-bit-integer-i128-work-on-a-64-bit-system&quot;&gt;answer&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;project-ideas&quot;&gt;Project Ideas&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;Given a list of integers, use a vector and return the mean (the average value), median (when sorted, the value in the middle position), and mode (the value that occurs most often) of the list.&lt;&#x2F;li&gt;
&lt;li&gt;Convert strings to pig latin. The first consonant of each word is moved to the end of the word and “ay” is added, so “first” becomes “irst-fay.” Words that start with a vowel have “hay” added to the end instead (“apple” becomes “apple-hay”).&lt;&#x2F;li&gt;
&lt;li&gt;Create a text interface to allow a user to add employee names to a department in a company. For example, “Add Sally to Engineering” or “Add Amir to Sales.” Then let the user retrieve a list of all people in a department or all people in the company by department, sorted alphabetically.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;links&quot;&gt;Links&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
(Finished: 2021-09-16) &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;book&#x2F;&quot;&gt;Rust Book&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
(Finished: 2021-09-16) &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rust-lang&#x2F;rustlings&#x2F;&quot;&gt;Rustlings&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
(Finished: 2021-09-17) &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-cli.github.io&#x2F;book&#x2F;&quot;&gt;Rust Cli&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
(Finished: 2021-09-18) &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;stable&#x2F;rust-by-example&#x2F;&quot;&gt;Rust By Example&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
(Finished: 2021-09-21) &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.apress.com&#x2F;gp&#x2F;book&#x2F;9781484255988&quot;&gt;Practical Rust Projects&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;&#x2F;&gt;
(Finished: 2021-09-27) &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.apress.com&#x2F;gp&#x2F;book&#x2F;9781484265888&quot;&gt;Practical Rust Web Projects&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;&#x2F;&gt;
(Finished: 2021-??-??) &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Dhghomon&#x2F;easy_rust&quot;&gt;easy-rust: simple language intro&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;&#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;fasterthanli.me&#x2F;tags&#x2F;rust&quot;&gt;fasterthanli&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;&#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;rust-lang-nursery.github.io&#x2F;rust-cookbook&#x2F;&quot;&gt;rust-cookbook&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;&#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.lpalmieri.com&#x2F;posts&#x2F;2020-05-24-zero-to-production-0-foreword&#x2F;&quot;&gt;zero-to-production&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;&#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;os.phil-opp.com&#x2F;t-cookbook&quot;&gt;Rust OS&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;&#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ctjhoa&#x2F;rust-learning&quot;&gt;rust-learning: a list of learning materials&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;&#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nostarch.com&#x2F;rust-rustaceans&quot;&gt;Rust for Rustaceans&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Easy election</title>
        <published>2021-09-26T00:00:00+00:00</published>
        <updated>2021-09-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-26/" type="text/html"/>
        <id>https://miku86.com/2021-09-26/</id>
        
        <content type="html">&lt;p&gt;Today we elect a new government in Germany.&lt;&#x2F;p&gt;
&lt;p&gt;This is the easiest vote I&#x27;ve ever made.&lt;&#x2F;p&gt;
&lt;p&gt;This is probably the first time I don&#x27;t think about myself, but about my children and their children.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s not about &amp;quot;Oh damn, I want to drive 150 km per hour, but I am only allowed to drive 130 km per hour, this is so mean.&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;It is about &amp;quot;Hey grandpa, all of you folks went to university, learned a lot about science and stuff.
Why have all of you been these idiots that didn&#x27;t stop this shitload of environmental pollution and useless, unfulfilling consumerism?
I&#x27;ve heard stories that you&#x27;ve had all this knowledge. Have you just been too lazy or too careless?&amp;quot;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Amish?</title>
        <published>2021-09-22T00:00:00+00:00</published>
        <updated>2021-09-22T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-22/" type="text/html"/>
        <id>https://miku86.com/2021-09-22/</id>
        
        <content type="html">&lt;p&gt;The more I learned about technology in the last few years, especially due my professional career, the more I started to reject digital stuff.&lt;&#x2F;p&gt;
&lt;p&gt;I think we&#x27;ve already peaked at the personal tech level some years ago, because new stuff is mostly (big) corporate controlled walled garden stuff (Google, Apple etc.).&lt;&#x2F;p&gt;
&lt;p&gt;Each time a new player comes around, big tech buys in and destroys it.&lt;&#x2F;p&gt;
&lt;p&gt;But big tech is not the problem - we are.&lt;&#x2F;p&gt;
&lt;p&gt;I once watched a documentary about Amish people.&lt;&#x2F;p&gt;
&lt;p&gt;Each time someone wanted to bring some new tech to their community, the elders went like &amp;quot;Alright, in 2 weeks at our weekly meeting, you can talk about this stuff and how this technology will benefit our community.&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;I like this approach.&lt;&#x2F;p&gt;
&lt;p&gt;Instead of mindlessly adding some new technologies without thinking about it up-front, the people actually have to think about the technology.&lt;&#x2F;p&gt;
&lt;p&gt;What&#x27;s the benefit for the community if I personally will own a smartphone and watch some memes all day long?&lt;&#x2F;p&gt;
&lt;p&gt;Sure, fun. But what will be the price I have to pay?&lt;&#x2F;p&gt;
&lt;p&gt;Are there other things, even non-tech, that will give me the same enjoyable feeling (like gardening, hiking etc.)?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Shady?</title>
        <published>2021-09-21T00:00:00+00:00</published>
        <updated>2021-09-21T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-21/" type="text/html"/>
        <id>https://miku86.com/2021-09-21/</id>
        
        <content type="html">&lt;p&gt;Sometimes I ask myself, if someone is a bad person, if they work for a company that does some kind of shady things.&lt;&#x2F;p&gt;
&lt;p&gt;Like nudging people to buy stuff they do not need, to watch ads for useless stuff etc.&lt;&#x2F;p&gt;
&lt;p&gt;Are there any companies that do not do shady stuff?&lt;&#x2F;p&gt;
&lt;p&gt;What does &amp;quot;shady&amp;quot; actually mean?&lt;&#x2F;p&gt;
&lt;p&gt;If my neighbor does shady stuff, then am I also allowed to do shady stuff?&lt;&#x2F;p&gt;
&lt;p&gt;Am I even not &amp;quot;clever&amp;quot;, if I do not do shady stuff, because everyone is doing it?&lt;&#x2F;p&gt;
&lt;p&gt;Am I guilty of being a part of a shady system?&lt;&#x2F;p&gt;
&lt;p&gt;Should I feel compassion for people who do not game the system (by doing shady stuff and letting society pay for it)?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Zola for my blog</title>
        <published>2021-09-07T00:00:00+00:00</published>
        <updated>2021-09-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-07/" type="text/html"/>
        <id>https://miku86.com/2021-09-07/</id>
        
        <content type="html">&lt;p&gt;This blog runs on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.getzola.org&#x2F;&quot;&gt;Zola&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve chosen it because it&#x27;s simple and fast.&lt;&#x2F;p&gt;
&lt;p&gt;My old blog was running with TypeScript, React and Gatsby.
Not bad, but the build time was very slow, around 3 minutes for 150 posts.&lt;&#x2F;p&gt;
&lt;p&gt;But that wasn&#x27;t my biggest concern: there was some feature creep and too many updates on the gatsby site.&lt;&#x2F;p&gt;
&lt;p&gt;I had some tests, but they were slow and I didn&#x27;t feel confident at all that after each week&#x27;s ~5 updates everything will run again.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I set up this simple blog and to get a better grasp of what is going on under the hood of Rust.&lt;&#x2F;p&gt;
&lt;p&gt;I don&#x27;t know if this will help my learning, but at least I feel confident, because my workflow goes like this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Copy an old post.&lt;&#x2F;li&gt;
&lt;li&gt;Add my new stuff.&lt;&#x2F;li&gt;
&lt;li&gt;Deploy (30 seconds of git add, commit, push, wait).&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>More Rust</title>
        <published>2021-09-06T00:00:00+00:00</published>
        <updated>2021-09-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-06/" type="text/html"/>
        <id>https://miku86.com/2021-09-06/</id>
        
        <content type="html">&lt;p&gt;I have a really simple plan for learning Rust:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;I read a chapter in the Rust Book&lt;&#x2F;li&gt;
&lt;li&gt;I do the Rustlings exercises that fit the chapter&#x27;s content&lt;&#x2F;li&gt;
&lt;li&gt;I summarize my learnings&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;After I will have finished the Rust Book and Rustlings, I will have a look into Rust By Example, Practical Rust and Codewars.&lt;&#x2F;p&gt;
&lt;p&gt;Today I worked on the Rustlings exercise about move, primitives and structs, enums and modules, because I&#x27;ve already read the book chapters until chapter 8.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Camping</title>
        <published>2021-09-05T00:00:00+00:00</published>
        <updated>2021-09-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-05/" type="text/html"/>
        <id>https://miku86.com/2021-09-05/</id>
        
        <content type="html">&lt;p&gt;I was on a camping trip for some days.&lt;&#x2F;p&gt;
&lt;p&gt;Camping is awesome.&lt;&#x2F;p&gt;
&lt;p&gt;Removing all this physical clutter and getting back to the basics: shelter, food and nice people.&lt;&#x2F;p&gt;
&lt;p&gt;We slept in a tent and we just lived with the bare minimum food: water, bread, cheese, rice, oats, veggies.&lt;&#x2F;p&gt;
&lt;p&gt;This is also my normal, healthy, 120€-per-month diet at home, so nothing new for me.&lt;&#x2F;p&gt;
&lt;p&gt;But after a hard day of hiking, this simple way of eating feels like heaven.&lt;&#x2F;p&gt;
&lt;p&gt;The first night was very uncomfortable, it was cold as hell.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why my first night back at home felt very cosy, in my nice, comfortable bed.&lt;&#x2F;p&gt;
&lt;p&gt;And my first meal back at home felt like eating out in a restaurant.&lt;&#x2F;p&gt;
&lt;p&gt;I think about most of my life in a relative perspective - I measure against other situations and events.&lt;&#x2F;p&gt;
&lt;p&gt;I think I need this kind of grounding to not lose my mind.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Projects: serial or parallel?</title>
        <published>2021-09-01T00:00:00+00:00</published>
        <updated>2021-09-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-09-01/" type="text/html"/>
        <id>https://miku86.com/2021-09-01/</id>
        
        <content type="html">&lt;p&gt;Because I&#x27;ve finished the udacity course the other day, I&#x27;m now focused on learning Rust.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m into serializing project, there is a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.ultraworking.com&#x2F;podcast&#x2F;mathematical-arguments-serializing-projects&quot;&gt;great podcast&lt;&#x2F;a&gt; about it.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s highly unlikely, that I like all my projects the same.&lt;&#x2F;p&gt;
&lt;p&gt;If I do them in parallel, I start giving all of them some time, but after some days and weeks, I lean towards fun, joy and convenience and mostly quit the not-so-enjoyable projects.&lt;&#x2F;p&gt;
&lt;p&gt;They sit around in the drawer and I feel bad about myself.&lt;&#x2F;p&gt;
&lt;p&gt;I am allowed to quit a project, but I don&#x27;t allow myself to juggle between the projects.&lt;&#x2F;p&gt;
&lt;p&gt;The decision has to be conscious. Yes or No. No &amp;quot;when I feel like it.&amp;quot;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>About Abstraction</title>
        <published>2021-08-31T00:00:00+00:00</published>
        <updated>2021-08-31T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-08-31/" type="text/html"/>
        <id>https://miku86.com/2021-08-31/</id>
        
        <content type="html">&lt;h2 id=&quot;when-code-evolves&quot;&gt;When code evolves&lt;&#x2F;h2&gt;
&lt;p&gt;We start out with a tiny function that doesn&#x27;t do that much (pseudo code):&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;function download_from_aws (from, to) {
  do_something();
  result = aws_client.download(from);
  parsed_result = parse(result);
  filesystem.write_to_disk(parsed_result, to);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So azure enters the room.&lt;&#x2F;p&gt;
&lt;p&gt;Time to DRY?&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;function download_from_cloud (from, to, provider) {
  do_something();

  switch provider:
    case PROVIDER.AWS: result = aws_client.download(from);
    case PROVIDER.AZURE: result = azure_client.download(from);

  parsed_result = parse(result);
  filesystem.write_to_disk(parsed_result, to);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Where should this live?&lt;&#x2F;li&gt;
&lt;li&gt;What happens in case of some conditional stuff, e.g. just &lt;code&gt;do_something()&lt;&#x2F;code&gt; for only &lt;code&gt;aws&lt;&#x2F;code&gt;?&lt;&#x2F;li&gt;
&lt;li&gt;Do we always either end up with a big god-like switch-festival or abstraction hell?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I don&#x27;t know.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Finished Nanodegree</title>
        <published>2021-08-30T00:00:00+00:00</published>
        <updated>2021-08-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-08-30/" type="text/html"/>
        <id>https://miku86.com/2021-08-30/</id>
        
        <content type="html">&lt;p&gt;I started the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.udacity.com&#x2F;course&#x2F;intro-to-cybersecurity-nanodegree--nd545&quot;&gt;Intro to Cybersecurity Nanodegree&lt;&#x2F;a&gt; some weeks ago and finished it today.&lt;&#x2F;p&gt;
&lt;p&gt;Just enrolled because of the flash sale back then, so ended up paying 270€.&lt;&#x2F;p&gt;
&lt;p&gt;The amount of content wa big, but the projects were often times ambigious in their tasks. Sometimes the downloads were messed up, e.g. wrong links.&lt;&#x2F;p&gt;
&lt;p&gt;In the original course, we had to create an account for Microsoft Azure to work with VMs.
Microsoft Azure is a pain in the ass (duplicate subscriptions, wrong receipts, broken web UI etc.).
Although the support people were nice and able to solve the wrong receipts, I will never use it again.&lt;&#x2F;p&gt;
&lt;p&gt;The automatically created course VMs were very slow (Windows 10 with 1GB RAM...) and horrible to work with.&lt;&#x2F;p&gt;
&lt;p&gt;One week ago, Udacity added cloud VMs, so we were able to connect to disposable VMs without an Azure account.
This improved the experience a lot, although I already finished the VM-intensive projects.&lt;&#x2F;p&gt;
&lt;p&gt;All in all, I&#x27;m &amp;quot;okay&amp;quot; with the content and the projects. But I would never ever again pay 270€ for this course. (already subtracted discount of 75%)&lt;&#x2F;p&gt;
&lt;p&gt;Next time, I will search on coursera and pay after some looks into course.&lt;&#x2F;p&gt;
&lt;p&gt;I love to pay for online teaching. If it&#x27;s worth the money.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Daily Schedule</title>
        <published>2021-08-24T00:00:00+00:00</published>
        <updated>2021-08-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-08-24/" type="text/html"/>
        <id>https://miku86.com/2021-08-24/</id>
        
        <content type="html">&lt;h2 id=&quot;daily-schedule&quot;&gt;Daily Schedule&lt;&#x2F;h2&gt;
&lt;p&gt;I started a new daily schedule this week.&lt;&#x2F;p&gt;
&lt;p&gt;First of all, I re-added free running sleep into my life - sleeping until I&#x27;ll wake up without an alarm.
This is a no-brainer. Sleep is very important and a lack of it leads to various bad things.&lt;&#x2F;p&gt;
&lt;p&gt;&amp;quot;I don&#x27;t have time to sleep&amp;quot; is actually a very weak excuse and a lack of maturity.
If I don&#x27;t have time to do one of the most fundamental things in life, I should take my time.&lt;&#x2F;p&gt;
&lt;p&gt;&amp;quot;Oversleeping&amp;quot; doesn&#x27;t exist. It&#x27;s just the homoestatic payment for my sleep deprivation.
It is not like overeating, because (industrial) food leads to emotional coping mechanisms and cravings.
But sleep does not.&lt;&#x2F;p&gt;
&lt;p&gt;So my schedule looks like this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Sleep: as long as I need, no alarm&lt;&#x2F;li&gt;
&lt;li&gt;Waking Hour 00-05: Creation: thinking, reading, day job (software engineering)&lt;&#x2F;li&gt;
&lt;li&gt;Waking Hour 05-09: Downtime: day job (emails, docs), strength training, eating, napping&lt;&#x2F;li&gt;
&lt;li&gt;Waking Hour 09-13: Creation: writing, private projects&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So far, it feels great. But I also know that every new approach feels great at first, because my brain has to defend its decisions.
I will see how this goes.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;supermemo&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Project Management, Signals</title>
        <published>2021-08-23T00:00:00+00:00</published>
        <updated>2021-08-23T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-08-23/" type="text/html"/>
        <id>https://miku86.com/2021-08-23/</id>
        
        <content type="html">&lt;h1 id=&quot;learnings&quot;&gt;Learnings&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;general&quot;&gt;General&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;default options are strong: I always ask myself, why people don&#x27;t use my cool, sophisticated software, but Windows 10 &#x2F; Edge &#x2F; Chrome &#x2F; Google Search &#x2F; whatever&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;project-management&quot;&gt;Project Management&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;we mostly use the tools we know, e.g. we default to Trello, Excel, Google Docs etc.&lt;&#x2F;li&gt;
&lt;li&gt;these tools shape how we think, e.g. &amp;quot;everything is a tablesheet, kanban etc.&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;most use of this software is fragile, because it is owned by for-profit companies and closed source -&amp;gt; moral dilemma: buyer&#x27;s need is not seller&#x27;s need&lt;&#x2F;li&gt;
&lt;li&gt;idea: use gitea&#x2F;gitlab&#x2F;github issues&lt;&#x2F;li&gt;
&lt;li&gt;pros: everything in one place, no sending of files (excel etc), no additional accounts (only on the git platform), connection between management and code, removes complexity through using markdown&lt;&#x2F;li&gt;
&lt;li&gt;cons: everyone needs an account, everyone has to learn simple markdown&lt;&#x2F;li&gt;
&lt;li&gt;use labels for categorical information (e.g. bug, feature), use milestones for time-bound chunks of work; do not use milestones for categorical information&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;commandline&quot;&gt;Commandline&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;signals: sigint, sigterm, sigkill&lt;&#x2F;li&gt;
&lt;li&gt;terminal multiplexer:
&lt;ul&gt;
&lt;li&gt;session (e.g. &amp;quot;work&amp;quot; or &amp;quot;personal&amp;quot;) -&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;window (e.g. &amp;quot;work&#x2F;rust&amp;quot; or &amp;quot;work&#x2F;nodejs&amp;quot;) -&amp;gt;&lt;&#x2F;li&gt;
&lt;li&gt;panel (e.g. &amp;quot;work&#x2F;rust&#x2F;main.rs&amp;quot; or &amp;quot;work&#x2F;rust&#x2F;lib.rs&amp;quot;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;why multiplexer instead of multiple window manager windows: not always access to window manager (e.g. on server), also increases complexity (more software)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;reading&quot;&gt;Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;https:&#x2F;&#x2F;blog.placemark.io&#x2F;2021&#x2F;07&#x2F;19&#x2F;issues-only-management.html&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Blog or Wiki?</title>
        <published>2021-08-22T00:00:00+00:00</published>
        <updated>2021-08-22T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-08-22/" type="text/html"/>
        <id>https://miku86.com/2021-08-22/</id>
        
        <content type="html">&lt;h1 id=&quot;concepts-multiple-notes-or-single-summary&quot;&gt;Concepts: multiple notes or single summary?&lt;&#x2F;h1&gt;
&lt;p&gt;I love to write down stuff. I am better at thinking than at memorizing, that&#x27;s why I have a big amount of notes on my local drive.&lt;&#x2F;p&gt;
&lt;p&gt;In the last few months and years, I had this habit of blogging nearly daily.&lt;&#x2F;p&gt;
&lt;p&gt;The last few months, there was something going on: complexity and my love for good organization.&lt;&#x2F;p&gt;
&lt;p&gt;I love to have a user-friendly, well-organized summaries of a topic, let&#x27;s call it &amp;quot;All I know about X&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;In my daily notes, I also want to write about small stuff, let&#x27;s say a newly learned shortcut for X.&lt;&#x2F;p&gt;
&lt;p&gt;Where should this new information live?&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;in the daily note: Sure, because I learned it today. But I learn everything on a specific day, so I would not be able to add anything to a summary.&lt;&#x2F;li&gt;
&lt;li&gt;in the summary: There are topics I&#x27;m heavily invested, e.g. Rust, Linux, nutrition, thinking, philosophy etc. There are also topics a &amp;quot;cheatsheet&amp;quot; is great, e.g. Vim. But I would always keep track which topics already have a summary, if&#x2F;when I can start a new summary etc.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Alright, probably a mixed approach makes sense: writing daily notes and if a topic is big enough, copying it into a summary.&lt;&#x2F;p&gt;
&lt;h1 id=&quot;implementation-blog-or-wiki&quot;&gt;Implementation: blog or wiki?&lt;&#x2F;h1&gt;
&lt;p&gt;The website I read the most: wikipedia.&lt;&#x2F;p&gt;
&lt;p&gt;I simply love it:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;clean, simple design&lt;&#x2F;li&gt;
&lt;li&gt;internal linking&lt;&#x2F;li&gt;
&lt;li&gt;free to use, free to share (https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License)&lt;&#x2F;li&gt;
&lt;li&gt;access to the data&#x27;s history&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Vim</title>
        <published>2021-08-21T00:00:00+00:00</published>
        <updated>2021-08-21T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-08-21/" type="text/html"/>
        <id>https://miku86.com/2021-08-21/</id>
        
        <content type="html">&lt;h1 id=&quot;shortcuts&quot;&gt;Shortcuts&lt;&#x2F;h1&gt;
&lt;pre&gt;&lt;code&gt;:help help
:q quit
:w write
:o open
esc escape mode
i insert mode
c - change mode
v - visual mode to select chars
V - visual line mode to select lines
vim tutor to learn
hjkl - left, down, up, right
u - undo
w - next start of word
b - last start of word
e - next end of word
f - find
x - delete char
dd - delete line
yy - copy line
yw - copy word
p - paste at cursor
P - paste before cursor
ctrl + r, 0 - paste in insert mode
r - replace with
3l - 3 times l key
di( - delete inside next (
da( - delete around next (
. - repeat last action
gg - go to start of file
G - go to end of file
dw: delete next (word)
ddp: swap lines
:% s&amp;#x2F;foo&amp;#x2F;bar&amp;#x2F;g: in all lines (`%`), `s`ubstitute (= search &amp;amp; replace) `foo` with `bar`
:% s&amp;#x2F;foo&amp;#x2F;bar&amp;#x2F;gc: in all lines (`%`), `s`ubstitute (= search &amp;amp; replace) `foo` with `bar`, ask for `c`onfirmation on each occurency
:1,$ s&amp;#x2F;foo&amp;#x2F;bar&amp;#x2F;g: from line `1` to the end (`$`), `s`ubstitute (= search &amp;amp; replace) `foo` with `bar`
:.,$ s&amp;#x2F;foo&amp;#x2F;bar&amp;#x2F;g: from the current line to the end (`$`), `s`ubstitute (= search &amp;amp; replace) `foo` with `bar`
:s&amp;#x2F;foo&amp;#x2F;bar&amp;#x2F;g: in the current line, `s`ubstitute (= search &amp;amp; replace) `foo` with `bar`
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;advanced&quot;&gt;Advanced&lt;&#x2F;h1&gt;
&lt;pre&gt;&lt;code&gt;- add text to multiple lines:
  - highlight multiple lines with Shift+V
  - type `:`: you will see `:&amp;#x27;&amp;lt;,&amp;#x27;&amp;gt;`
  - type `norm A`: this goes into `norm`al mode and `A`ppends to the end of the line
  - type whatever you want to add
  - example: `:&amp;#x27;&amp;lt;,&amp;#x27;&amp;gt;norm A;`: adds a `;` to the end
  - you can do the same for the start of a line by using replacing `A` with `I`
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h1 id=&quot;links&quot;&gt;Links&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;https:&#x2F;&#x2F;vimawesome.com&#x2F;&lt;&#x2F;li&gt;
&lt;li&gt;https:&#x2F;&#x2F;vim-adventures.com&#x2F;&lt;&#x2F;li&gt;
&lt;li&gt;http:&#x2F;&#x2F;www.vimgolf.com&#x2F;&lt;&#x2F;li&gt;
&lt;li&gt;https:&#x2F;&#x2F;vim.fandom.com&#x2F;wiki&#x2F;Search_and_replace&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Tmux</title>
        <published>2021-08-20T00:00:00+00:00</published>
        <updated>2021-08-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-08-20/" type="text/html"/>
        <id>https://miku86.com/2021-08-20/</id>
        
        <content type="html">&lt;h1 id=&quot;ideas&quot;&gt;Ideas&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;this is just my mental model, build your own&lt;&#x2F;li&gt;
&lt;li&gt;life can be thought about in different environments, let&#x27;s call them &lt;code&gt;sessions&lt;&#x2F;code&gt;; example: work environment, private environment, gym environment&lt;&#x2F;li&gt;
&lt;li&gt;an environment can be divided into different projects, let&#x27;s call them &lt;code&gt;windows&lt;&#x2F;code&gt;; example: work&#x2F;client A, work&#x2F;client B, private&#x2F;hobby A&lt;&#x2F;li&gt;
&lt;li&gt;a project can be divided into different tasks, let&#x27;s call them &lt;code&gt;panes&lt;&#x2F;code&gt;; example: work&#x2F;client A&#x2F;add feature A, work&#x2F;client B&#x2F;add feature Z, private&#x2F;hobby A&#x2F;do workout D&lt;&#x2F;li&gt;
&lt;li&gt;so I have different sessions, e.g. working on a tool, writing my blog&lt;&#x2F;li&gt;
&lt;li&gt;when I want to work on my tool, I hit &lt;code&gt;mod + s&lt;&#x2F;code&gt; to show my sessions and then change to my &amp;quot;work on my tool&amp;quot; session, with all the tools set up&lt;&#x2F;li&gt;
&lt;li&gt;when I want to switch to writing my blog, I hit &lt;code&gt;mod + s&lt;&#x2F;code&gt; again and go to my &amp;quot;write my blog&amp;quot; session, with all the tools set up&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;shortcuts&quot;&gt;Shortcuts&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;mod&lt;&#x2F;code&gt; stands for &lt;code&gt;modifier key&lt;&#x2F;code&gt;; the default &lt;code&gt;modifier key&lt;&#x2F;code&gt; is &lt;code&gt;ctrl + b&lt;&#x2F;code&gt;, I changed mine to &lt;code&gt;ctrl +  a&lt;&#x2F;code&gt; for ergonomics&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;example: when I write &lt;code&gt;mod + x&lt;&#x2F;code&gt;, then hit your modifier key (defaults to &lt;code&gt;ctrl + b&lt;&#x2F;code&gt;) and &lt;code&gt;x&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;all shortcuts: &lt;code&gt;mod + ?&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;show all sessions: &lt;code&gt;mod + s&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;new window: &lt;code&gt;mod + c&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;kill window: &lt;code&gt;mod + x&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;go to &lt;code&gt;n&lt;&#x2F;code&gt;ext pane: &lt;code&gt;mod + n&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;go to &lt;code&gt;p&lt;&#x2F;code&gt;revious pane: &lt;code&gt;mod + p&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;scroll up&#x2F;down: &lt;code&gt;mod, pageup&#x2F;pagedown&lt;&#x2F;code&gt;, quit: &lt;code&gt;q&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h1 id=&quot;links&quot;&gt;Links&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;tmux faq&lt;&#x2F;li&gt;
&lt;li&gt;github SetupNotes&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Facebook leak</title>
        <published>2021-04-07T00:00:00+00:00</published>
        <updated>2021-04-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-04-07/" type="text/html"/>
        <id>https://miku86.com/2021-04-07/</id>
        
        <content type="html">&lt;p&gt;You probably already heard about it: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=26681969&quot;&gt;533M Facebook users&#x27; data leaked&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;So the Wikipedia articles about &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Criticism_of_Facebook&quot;&gt;Critism&lt;&#x2F;a&gt; and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Privacy_concerns_of_Facebook&quot;&gt;Privacy concerns&lt;&#x2F;a&gt; of Facebook are already very long. One new chapter added.&lt;&#x2F;p&gt;
&lt;p&gt;In May, WhatsApp will &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.dw.com&#x2F;en&#x2F;whatsapp-delays-privacy-changes-following-backlash&#x2F;a-56243714&quot;&gt;update their terms of service&lt;&#x2F;a&gt;, so Facebook will get your WhatsApp data.&lt;&#x2F;p&gt;
&lt;p&gt;Data of a mass surveillance tool (WhatsApp) in the hands of a company (Facebook) that sells and loses your data.&lt;&#x2F;p&gt;
&lt;p&gt;I think it&#x27;s time to make a decision.&lt;&#x2F;p&gt;
&lt;p&gt;I made my decision some days ago, but it was in the making for a long time:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;2021-04-02&quot;&gt;I deleted WhatsApp&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;2021-04-03&quot;&gt;Why I deleted WhatsApp&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Password manager housecleaning</title>
        <published>2021-04-06T00:00:00+00:00</published>
        <updated>2021-04-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-04-06/" type="text/html"/>
        <id>https://miku86.com/2021-04-06/</id>
        
        <content type="html">&lt;p&gt;Last year, I migrated all my passwords from Firefox to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;KeePassXC&quot;&gt;KeePassXC&lt;&#x2F;a&gt; to have my passwords just saved locally, not in the hands of a third party.&lt;&#x2F;p&gt;
&lt;p&gt;Yesterday, I had a look into the database - 115 entries.&lt;&#x2F;p&gt;
&lt;p&gt;So looking at this data, I saw a lot of unused stuff, e.g. Zoom, some email accounts, some old tools and so on.&lt;&#x2F;p&gt;
&lt;p&gt;So I decided to do some housecleaning by deleting some of these accounts.&lt;&#x2F;p&gt;
&lt;p&gt;Before deleting the account, I set the account email address to something like &lt;code&gt;zoom-2021-04-06@mydomain.com&lt;&#x2F;code&gt; to have an unique address for each account.&lt;&#x2F;p&gt;
&lt;p&gt;Why? Because I hope to see, which company sells&#x2F;leaks my email and&#x2F;or doesn&#x27;t delete it at all. This company will go to my personal &amp;quot;black list&amp;quot; of not trustworthy companies.&lt;&#x2F;p&gt;
&lt;p&gt;Some companies are already very sneaky:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;clicking on the deletion button doesn&#x27;t work, even in different browsers&lt;&#x2F;li&gt;
&lt;li&gt;the captcha isn&#x27;t solvable, even after trying it for 10 minutes (no joke!)&lt;&#x2F;li&gt;
&lt;li&gt;trying to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Nudge_theory&quot;&gt;nudge me&lt;&#x2F;a&gt; with a blue, bold button to cancel the deletion and a just slightly-visible button to accept the deletion&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Whatever, I managed to delete 13 accounts.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>First SMS, deleted Twitter</title>
        <published>2021-04-05T00:00:00+00:00</published>
        <updated>2021-04-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-04-05/" type="text/html"/>
        <id>https://miku86.com/2021-04-05/</id>
        
        <content type="html">&lt;p&gt;I&#x27;ve just sent my first SMS after like 3 years. (christmas 2017)&lt;&#x2F;p&gt;
&lt;p&gt;My phone plan has some of them included, so I even don&#x27;t have to pay additional money.&lt;&#x2F;p&gt;
&lt;p&gt;Yes, SMS are not encrypted, so a good reason not to send too much of them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;I also deleted my Twitter account. It&#x27;s a big rabbit hole, especially being outraged about idiots.&lt;&#x2F;p&gt;
&lt;p&gt;I downloaded my account data. I can see a &amp;quot;personalization&amp;quot; list with topics Twitter thinks I like &#x2F; will buy.&lt;&#x2F;p&gt;
&lt;p&gt;90% of this list is just plain wrong:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;some cryptocurrencies (total waste of energy)&lt;&#x2F;li&gt;
&lt;li&gt;big company stocks (just no!)&lt;&#x2F;li&gt;
&lt;li&gt;rubbish, fancy food (I am a healthy, but simple person)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I also had a look into the &amp;quot;Ad Engagements&amp;quot; list. I just had to laugh out loud. I hope none of these companies ever paid money to show me these ads. One company bought 37% of all my ad space. I don&#x27;t know this company and I don&#x27;t do anything in the field they work in.&lt;&#x2F;p&gt;
&lt;p&gt;Sure, maybe I&#x27;m an outlier (or I&#x27;m too confident I won&#x27;t ever buy this stuff), and this works even without me. But in a perfect world, we don&#x27;t have to bear this manipulating ads game.&lt;&#x2F;p&gt;
&lt;p&gt;But instead of being outraged and doing nothing, I will save my energy and will invest it into making the world a better place.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;As I said &lt;a href=&quot;&#x2F;blog&#x2F;2021-04-04&quot;&gt;yesterday&lt;&#x2F;a&gt;, being intentional is very important.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I created a Friendica account some weeks ago.&lt;&#x2F;p&gt;
&lt;p&gt;Why? Because it&#x27;s a social network like Facebook, but it has one killer feature: You can subscribe to other platforms. So I am subscribed to accounts on YouTube, Twitter, Mastodon etc.&lt;&#x2F;p&gt;
&lt;p&gt;These platforms don&#x27;t get my behavioral data, so they can&#x27;t sell my attention.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Digital minimalism algorithm</title>
        <published>2021-04-04T00:00:00+00:00</published>
        <updated>2021-04-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-04-04/" type="text/html"/>
        <id>https://miku86.com/2021-04-04/</id>
        
        <content type="html">&lt;p&gt;I continued on reading &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.goodreads.com&#x2F;book&#x2F;show&#x2F;40672036-digital-minimalism&quot;&gt;Cal Newport - Digital Minimalism&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The algorithm to decide which tool to use and how to use it boils down to:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Does this tech directly support one deep value?&lt;&#x2F;li&gt;
&lt;li&gt;Is this tech the best way to support this value?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;If both are a &amp;quot;Yes&amp;quot;, then go to:&lt;&#x2F;p&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;How can I use it to maximize the value and minimize the harm?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;If one is &amp;quot;No&amp;quot;, go back to start and think about something else.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Examples:&lt;&#x2F;p&gt;
&lt;p&gt;I have the deep value to stay connected with friend X.&lt;&#x2F;p&gt;
&lt;p&gt;The tech I want to choose: WhatsApp.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Does this tech directly support one deep value? Yes.&lt;&#x2F;li&gt;
&lt;li&gt;Is this tech the best way to support this value? Probably not, it&#x27;s privacy invasive, uses some dark patterns and increases a monopoly.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;The alternative: Calling.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Does this tech directly support one deep value? Yes.&lt;&#x2F;li&gt;
&lt;li&gt;Is this tech the best way to support this value? Probably yes, because it&#x27;s more intense than just texting and I just need like 15min each 2 weeks. There are probably no dark patterns and the telecommunication market is not a monopoly (at least in germany).&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Because it&#x27;s not just black and white, we could also add &amp;quot;meeting in real life&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;In the end this is about being very intentional about the tech.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I don&#x27;t have to ditch WhatsApp completely, but being more intentional about my usage makes a lot of sense to me.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Why I deleted WhatsApp</title>
        <published>2021-04-03T00:00:00+00:00</published>
        <updated>2021-04-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-04-03/" type="text/html"/>
        <id>https://miku86.com/2021-04-03/</id>
        
        <content type="html">&lt;p&gt;Yesterday, I talked about the fact, &lt;strong&gt;that&lt;&#x2F;strong&gt; I deleted WhatsApp.&lt;&#x2F;p&gt;
&lt;p&gt;Today, I want to talk about the &lt;strong&gt;why&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Some people asked me why I just do not keep WhatsApp closed, because I &amp;quot;force&amp;quot; other people to use Signal or maybe pay money (phone&#x2F;SMS).&lt;&#x2F;p&gt;
&lt;p&gt;And that&#x27;s a totally viable question.&lt;&#x2F;p&gt;
&lt;p&gt;My thoughts are like this: I started to use Signal in parallel with WhatsApp. Around 10% of my contacts were in Signal, so I talked to them there.&lt;&#x2F;p&gt;
&lt;p&gt;Many conversations started in Signal, but flowed back to WhatsApp. Sometimes because people were more trained with the UI of WhatsApp. Sometimes because they wanted to share stuff from WhatsApp and the share option showed my WhatsApp account first. Sometime because I was their only contact in Signal and they wanted to have everything in WhatsApp.&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, there are many causes that led to going back to WhatsApp.&lt;&#x2F;p&gt;
&lt;p&gt;There are also bigger issues: When you are a person who wants to start using messengers, you probably choose the platform where your friends are. Currently, WhatsApp has 2B users and Signal &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.businessofapps.com&#x2F;data&#x2F;signal-statistics&#x2F;&quot;&gt;40M users&lt;&#x2F;a&gt;, so that&#x27;s just 2% of WhatsApp.&lt;&#x2F;p&gt;
&lt;p&gt;If everyone is on platform A, new people will also join platform A, so this is - in practice - a monopoly, because it gets bigger and bigger. In theory, there are other market players, but this is a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Chicken_or_the_egg&quot;&gt;&amp;quot;chicken or egg&amp;quot;-problem&lt;&#x2F;a&gt;: If there are no existing people on platform B, new people also don&#x27;t join. And if no new people join platform B, there won&#x27;t be existing people.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;To break out of this loop, I think there is only one solution: don&#x27;t use the monopoly.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As long as you are available there, other people won&#x27;t feel the need to join other platforms. I also think I am too &amp;quot;weak&amp;quot; to not use it if it is available to me, especially with all the social pressure that keeps coming in.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;But what happens when Signal would become the new monopoly? Should we change our platform again?&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s a good questions, too!&lt;&#x2F;p&gt;
&lt;p&gt;I think the problem with WhatsApp is the fact, that it is a monopoly &lt;em&gt;and&lt;&#x2F;em&gt; is owned by a publicly traded company, Facebook.&lt;&#x2F;p&gt;
&lt;p&gt;Why is this a problem?&lt;&#x2F;p&gt;
&lt;p&gt;Because a publicly traded company has the (primary?) goal of making money. And making money with a free app is probably not so easy, so a lot of moral dilemmas can emerge.&lt;&#x2F;p&gt;
&lt;p&gt;What happens when a feature is good for making money, but bad for the users?&lt;&#x2F;p&gt;
&lt;p&gt;For example, the functionality to export your data and move it to another platform is an awesome feature for users. But it is really bad for making money, because people can easily walk away. If there isn&#x27;t such a functionality, people maybe want to walk away, but are forced to stay with their current platform, because they don&#x27;t want to lose their chat content.&lt;&#x2F;p&gt;
&lt;p&gt;What happens when a big financial investor changes their attitude towards the platform?&lt;&#x2F;p&gt;
&lt;p&gt;For example, the investor wants to make more money now and votes for letting the users pay $10 per year? For WhatsApp, this would be a revenue increase of $20 B per year (2B users * $10 &#x2F; year). I think most people would pay this money, because migrating to another platform, losing all their data and learning a new platform is probably too much.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;This is why I think (psychologically) &amp;quot;critical&amp;quot; infrastructure should not by owned be publicly traded companies that are not owned by the country&#x2F;people.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Deleted WhatsApp</title>
        <published>2021-04-02T00:00:00+00:00</published>
        <updated>2021-04-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-04-02/" type="text/html"/>
        <id>https://miku86.com/2021-04-02/</id>
        
        <content type="html">&lt;p&gt;Today, I finally deleted my WhatsApp account.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;ve been a user of WhatsApp for nearly 10 years. I actually paid 0.89€ for the app.&lt;&#x2F;p&gt;
&lt;p&gt;It was a game changer back in the days, because I grew up paying 0.49€ for each message (SMS). So due WhatsApp, I just had to pay my monthly data and was able to send unlimited messages.&lt;&#x2F;p&gt;
&lt;p&gt;I actually liked the functionality of the app, e.g. having groups, broadcasts and stuff.&lt;&#x2F;p&gt;
&lt;p&gt;I remember the acquisition of WhatsApp by Facebook and all the news about it, like &amp;quot;Why do they pay 19 Billion Dollars for a free app?&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;I think we all know why Facebook did this.&lt;&#x2F;p&gt;
&lt;p&gt;WhatsApp had &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Whatsapp#User_statistics&quot;&gt;2 Billion users&lt;&#x2F;a&gt; at the beginning of 2020, 25% of the world&#x27;s population. Meta data of 2 Billion people who probably use it each day. Now add this to the data of 2.8B Facebook users and 1.0B Instagram users.&lt;&#x2F;p&gt;
&lt;p&gt;This data is in the hands of a company, that made a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Facebook,_Inc.&quot;&gt;net income of 29 Billion dollar in 2020&lt;&#x2F;a&gt; with just free user services (and selling a small amount of VR hardware).&lt;&#x2F;p&gt;
&lt;p&gt;So how did I do this?&lt;&#x2F;p&gt;
&lt;p&gt;I sent a personal message to each contact and to my groups, stating that I will delete my account and they can reach me on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;signal.org&#x2F;install&#x2F;&quot;&gt;Signal&lt;&#x2F;a&gt; or by phone&#x2F;SMS. ~50% of my contacts joined Signal after this message.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Reading long-form content vs. short-news</title>
        <published>2021-04-01T00:00:00+00:00</published>
        <updated>2021-04-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-04-01/" type="text/html"/>
        <id>https://miku86.com/2021-04-01/</id>
        
        <content type="html">&lt;p&gt;Reading is an integral part of my life. I do this since I was a small kid, I visited our local library each monday.&lt;&#x2F;p&gt;
&lt;p&gt;For some months back in 2019, I read for 2 (!) hours every morning in bed - hackernews, reddit and so on. But because it was &amp;quot;tech-related&amp;quot;, I never questioned these readings.&lt;&#x2F;p&gt;
&lt;p&gt;Last year, especially due Corona, I started to think more about my media consumption.&lt;&#x2F;p&gt;
&lt;p&gt;I still read a lot, but I saw changes in my reading habit: from long-form content to clickbait short-news.&lt;&#x2F;p&gt;
&lt;p&gt;I never made these changes intentionally, the devices and platforms just sucked me in.&lt;&#x2F;p&gt;
&lt;p&gt;It was painful to acknowledge that I was not able to sit down for 5min at the table to read a book. Seeing this after I&#x27;ve read over 200 books in my life was a devastating feeling.&lt;&#x2F;p&gt;
&lt;p&gt;I always felt this urge to check for news. I was like &amp;quot;Hey, it&#x27;s Corona time, so it&#x27;s my civil duty to stay informed.&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;But staying informed is probably not the same as reading clickbait stories...&lt;&#x2F;p&gt;
&lt;p&gt;This is why I - again - started to read more long-form content last year.&lt;&#x2F;p&gt;
&lt;p&gt;Currently, I&#x27;m reading &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.goodreads.com&#x2F;book&#x2F;show&#x2F;39778359-die-daten-die-ich-rief&quot;&gt;(German) Katharina Nocun - Die Daten, die ich rief&lt;&#x2F;a&gt;. It&#x27;s about our data, privacy and the economy around it.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>New job, &#x27;just 5min&#x27;-approach</title>
        <published>2021-03-31T00:00:00+00:00</published>
        <updated>2021-03-31T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-31/" type="text/html"/>
        <id>https://miku86.com/2021-03-31/</id>
        
        <content type="html">&lt;p&gt;I visited a company that invited me to work with them. Small team, cool stuff, a lot to learn, very generalist role, part-time. Seems perfect to me.&lt;&#x2F;p&gt;
&lt;p&gt;Afterwards I kept my biking streak alive. The hardest part is to start.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;I use the &amp;quot;just go outside for 5min&amp;quot;-approach.&lt;&#x2F;strong&gt;
When fun kicks in, it seems to be easy to ride for 30-60min.&lt;&#x2F;p&gt;
&lt;p&gt;Then I tried to run the Taiga docker. Some progress, but still breaking. Will work on this tomorrow.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Proxy, Pi-hole, Nextcloud working + Workshop</title>
        <published>2021-03-30T00:00:00+00:00</published>
        <updated>2021-03-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-30/" type="text/html"/>
        <id>https://miku86.com/2021-03-30/</id>
        
        <content type="html">&lt;p&gt;I updated my whole selfhosted scripts: Caddy, Pi-hole and Nextcloud work out-of-the-box with my install script.
It also creates the environmental stuff (network etc.) and gives some feedback.&lt;&#x2F;p&gt;
&lt;p&gt;I also found a cool tool called &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;moncho&#x2F;dry&quot;&gt;dry&lt;&#x2F;a&gt; to manage my docker stuff in the terminal.&lt;&#x2F;p&gt;
&lt;p&gt;In the evening I hosted my regular workshop, where we build a JS application. Teaching is very important to me. The feedback loops are awesome and I learn a lot for my own personal development.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>My shortlist and riding my bike</title>
        <published>2021-03-29T00:00:00+00:00</published>
        <updated>2021-03-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-29/" type="text/html"/>
        <id>https://miku86.com/2021-03-29/</id>
        
        <content type="html">&lt;p&gt;I have a list with short tasks I want to work &#x2F; research on. From time to time I give myself some hours to do this stuff.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s mostly simple stuff like &amp;quot;Have a look at website X&amp;quot; or &amp;quot;Do laundry&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;So why do I have a list for this stuff? I mean most people probably don&#x27;t have a list to remember doing laundry, but they do it anyway.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;I do this to keep up my focus.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Sure, I would do it at some point, e.g. when I would &lt;em&gt;feel&lt;&#x2F;em&gt; like doing it. But this is also how &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Binge_watching&quot;&gt;binge-watching&lt;&#x2F;a&gt; and social media madness creeps into life, &amp;quot;I currently feel like I should spend 4 hours on reddit to watch some funny memes.&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;So I plan this shortlist stuff, I give it a dedicated place in my calendar.&lt;&#x2F;p&gt;
&lt;p&gt;I also do this with exercising. I have an appointment with myself each day at 3PM to ride my bike. Yes, sometimes I can&#x27;t make it at 3 or I simply &amp;quot;forget&amp;quot; it, because I don&#x27;t look into my calendar. But these days are rare. It&#x27;s not about perfection, &lt;strong&gt;it&#x27;s about the trend &amp;amp; creating a habit.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How much should I ...?</title>
        <published>2021-03-28T00:00:00+00:00</published>
        <updated>2021-03-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-28/" type="text/html"/>
        <id>https://miku86.com/2021-03-28/</id>
        
        <content type="html">&lt;p&gt;Yesterday was a great day, weather-wise.&lt;&#x2F;p&gt;
&lt;p&gt;But I was working on my selfhosting project all day long. I actually was scheduled to meet friends in the evening and just worked on my stuff from 10AM to 7PM.&lt;&#x2F;p&gt;
&lt;p&gt;So is this worth it, &amp;quot;wasting&amp;quot; a sunny day and instead doing some computer work? Good question.&lt;&#x2F;p&gt;
&lt;p&gt;Sometimes it is worth it, sometimes not.&lt;&#x2F;p&gt;
&lt;p&gt;I think a lot about these lifestyle choices.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;How much should I work for a living?&lt;&#x2F;li&gt;
&lt;li&gt;How much should I volunteer? (e.g. to free and open source software)&lt;&#x2F;li&gt;
&lt;li&gt;How much should I meet friends?&lt;&#x2F;li&gt;
&lt;li&gt;How much should I work out?&lt;&#x2F;li&gt;
&lt;li&gt;How much should I be in the nature?&lt;&#x2F;li&gt;
&lt;li&gt;How much should I think about how I should spend my time?&lt;&#x2F;li&gt;
&lt;li&gt;How much should I ...?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Which proxy?</title>
        <published>2021-03-27T00:00:00+00:00</published>
        <updated>2021-03-27T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-27/" type="text/html"/>
        <id>https://miku86.com/2021-03-27/</id>
        
        <content type="html">&lt;p&gt;So I decided to work on the single applications (Pi-hole, Nextcloud, Taiga) first.&lt;&#x2F;p&gt;
&lt;p&gt;Pi-hole and Nextcloud work out-of-the-box by using the official docker images (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;pi-hole&#x2F;docker-pi-hole&quot;&gt;Pi-hole&lt;&#x2F;a&gt;, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;nextcloud&#x2F;docker&quot;&gt;Nextcloud&lt;&#x2F;a&gt;). Couldn&#x27;t get the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;taigaio&#x2F;taiga-docker&quot;&gt;Taiga docker image&lt;&#x2F;a&gt; to work.&lt;&#x2F;p&gt;
&lt;p&gt;But that&#x27;s a good opportunity to learn more about debugging docker.&lt;&#x2F;p&gt;
&lt;p&gt;I switched to start adding the proxy.&lt;&#x2F;p&gt;
&lt;p&gt;Had a look at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Nginx&quot;&gt;nginx&lt;&#x2F;a&gt;, it just worked.&lt;&#x2F;p&gt;
&lt;p&gt;But because this is a long-term project, I searched for something more &amp;quot;modern&amp;quot; aka &amp;quot;built for containers&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;So I also had a look into &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;traefik&#x2F;traefik&quot;&gt;traefik&lt;&#x2F;a&gt;. Some hours later I had read through the whole docs, but I only made it happen to run some simple examples, but not traefik + pi-hole + nextcloud in an automaticed way.&lt;&#x2F;p&gt;
&lt;p&gt;Next stop: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Caddy_(web_server)&quot;&gt;Caddy&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Selfhosting my stuff</title>
        <published>2021-03-26T00:00:00+00:00</published>
        <updated>2021-03-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-26/" type="text/html"/>
        <id>https://miku86.com/2021-03-26/</id>
        
        <content type="html">&lt;p&gt;As you can see on my &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;uses&#x2F;&quot;&gt;&amp;quot;uses&amp;quot;-page&lt;&#x2F;a&gt;, I&#x27;m into free and open-source software and privacy.&lt;&#x2F;p&gt;
&lt;p&gt;I already host my &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pi-hole&quot;&gt;Pi-hole&lt;&#x2F;a&gt; adblocker at home. My &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Nextcloud&quot;&gt;Nextcloud&lt;&#x2F;a&gt; cloud is on my own VPS, my &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Taiga_(project_management)&quot;&gt;Taiga&lt;&#x2F;a&gt; project management is on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;disroot.org&#x2F;&quot;&gt;disroot&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;My next goal is to run all these services at home. It just feels better to have my data at home, not on the public internet, especially &lt;strong&gt;sensitive data like my calendar and my contacts&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I currently build my setup like this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Service #1: Pihole&lt;&#x2F;li&gt;
&lt;li&gt;Service #2: Nextcloud&lt;&#x2F;li&gt;
&lt;li&gt;Service #3: Taiga&lt;&#x2F;li&gt;
&lt;li&gt;Proxy: ?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Over the last few days I&#x27;ve been doing a bunch of stuff with Docker to make it work automatically and reliably.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to have a look at free and open source software to leave all this privacy-invasive stuff behind you,
have a look at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;awesome-selfhosted&#x2F;awesome-selfhosted&quot;&gt;Awesome Selfhosted&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Being in public like a pro</title>
        <published>2021-03-25T00:00:00+00:00</published>
        <updated>2021-03-25T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-25/" type="text/html"/>
        <id>https://miku86.com/2021-03-25/</id>
        
        <content type="html">&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;2021-03-24&quot;&gt;Yesterday&lt;&#x2F;a&gt; I published my first daily post again.&lt;&#x2F;p&gt;
&lt;p&gt;This feels like a commitment to do this in public.
I&#x27;ve always kept up the habit of writing, but I didn&#x27;t publish it.&lt;&#x2F;p&gt;
&lt;p&gt;Maybe some fear of being not interesting enough while people on Instagram or TikTok do all this fancy stuff. But this is probably not reality and I very rarely check these platforms.&lt;&#x2F;p&gt;
&lt;p&gt;To get news, I use &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Friendica&quot;&gt;Friendica&lt;&#x2F;a&gt;, where I subscribe to accounts on YouTube, Twitter, RSS Feeds, Mastodon etc.&lt;&#x2F;p&gt;
&lt;p&gt;If I want to write on Twitter, I use &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tweetdeck.twitter.com&#x2F;&quot;&gt;Tweetdeck&lt;&#x2F;a&gt;, so I never see trends or other outraging stuff. I try to use it like a professional.&lt;&#x2F;p&gt;
&lt;p&gt;How do you handle social media?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Daily diary again</title>
        <published>2021-03-24T00:00:00+00:00</published>
        <updated>2021-03-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-03-24/" type="text/html"/>
        <id>https://miku86.com/2021-03-24/</id>
        
        <content type="html">&lt;p&gt;I will restart my daily diary again.&lt;&#x2F;p&gt;
&lt;p&gt;I think I answered some of &lt;a href=&quot;&#x2F;blog&#x2F;day-2020-11-18&quot;&gt;my questions&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;My mind is interesting. Biased all the way.&lt;&#x2F;p&gt;
&lt;p&gt;My diary is a way to look back and check reality.&lt;&#x2F;p&gt;
&lt;p&gt;Is this how it was back then? Are my memories exact?&lt;&#x2F;p&gt;
&lt;p&gt;Writing is some sort of meditation. While writing this post, I let my hands go and my thoughts flow. Some of the stuff feels &amp;quot;weird&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;Like when I wake up at night and think about stuff that matters to me. When my conscious mind is not a filter to my inner me. These moments are rare.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Why do I even write this daily diary?&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;&lt;strong&gt;To get in touch with myself.&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>#100DaysOfHaskell: Start</title>
        <published>2021-02-16T00:00:00+00:00</published>
        <updated>2021-02-16T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-02-16/" type="text/html"/>
        <id>https://miku86.com/2021-02-16/</id>
        
        <content type="html">&lt;p&gt;When you have a look at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&quot;&gt;all my post&lt;&#x2F;a&gt;, you can see that many of them are about JavaScript.&lt;&#x2F;p&gt;
&lt;p&gt;The more I&#x27;ve grown as an engineer&#x2F;developer, the more I&#x27;ve moved away from caring too much about implementation details.&lt;&#x2F;p&gt;
&lt;p&gt;Tools like languages, frameworks and libraries come and go, but ideas, concepts and patterns stay way longer.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I&#x27;m very open-minded towards learning new concepts.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Functional_programming&quot;&gt;Functional Programming&lt;&#x2F;a&gt; is one of these concepts I find very interesting and intuitive.&lt;&#x2F;p&gt;
&lt;p&gt;Nowadays I&#x27;m more into &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&#x2F;&quot;&gt;mentoring&lt;&#x2F;a&gt;, especially about ideas and concepts, so I don&#x27;t program that much.&lt;&#x2F;p&gt;
&lt;p&gt;What do I do? So I already did a lot of functional programming in JavaScript and TypeScript, because this is what you use when you do a lot of React stuff, but I want to fully immerse into functional programming, not just when I need it.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I decided to have a look at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Haskell_(programming_language)&quot;&gt;Haskell&lt;&#x2F;a&gt; and I just started a &lt;code&gt;#100DaysOfHaskell&lt;&#x2F;code&gt; challenge. Because I want to see these new concepts in action, I try do some programming with Haskell every day.&lt;&#x2F;p&gt;
&lt;p&gt;You will see my progress from time to time on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&quot;&gt;my blog&lt;&#x2F;a&gt; and live on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;miku86com&#x2F;status&#x2F;1356505938144935936&quot;&gt;twitter&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Currently, my code is on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&quot;&gt;repl.it&lt;&#x2F;a&gt; until I&#x27;ll find a better solution. If you know about a better solution (the code breaks when you hit the &lt;code&gt;run&lt;&#x2F;code&gt; button), let me know!&lt;&#x2F;p&gt;
&lt;p&gt;Send me a tweet or a message if you&#x27;ve got some ideas or questions!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How I learn</title>
        <published>2021-01-26T00:00:00+00:00</published>
        <updated>2021-01-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-01-26/" type="text/html"/>
        <id>https://miku86.com/2021-01-26/</id>
        
        <content type="html">&lt;p&gt;One of the most popular questions I get as a mentor is &amp;quot;Why do you know so much stuff and how can you learn stuff so quickly?&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;I also often see people who struggle with learning, e.g. on the FreeCodeCamp forum and on Twitter.&lt;&#x2F;p&gt;
&lt;p&gt;This is why I want to write down my thoughts and experiences about this topic. Especially because I think about this a lot lately and I want to practice &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;when-to-write-a-blog-post&quot;&gt;what I preach&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;&lt;strong&gt;First things first&lt;&#x2F;strong&gt;: This is a lot about self-awareness and trial &amp;amp; error. These are just my ideas. I invite you to show me yours.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;formats&quot;&gt;Formats&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;video&quot;&gt;Video&lt;&#x2F;h2&gt;
&lt;p&gt;Everything seems to be video (courses) nowadays.&lt;&#x2F;p&gt;
&lt;p&gt;I also used to like video courses. I could do this while travelling by train, lying in bed etc.&lt;&#x2F;p&gt;
&lt;p&gt;But this is also the biggest problem. It&#x27;s just consuming. I just consume information. Sometimes even if I&#x27;m distracted.&lt;&#x2F;p&gt;
&lt;p&gt;And that&#x27;s the deceptive and very problematic issue with video for me. I do stuff, but it seems to be mostly useless. There is no active thinking involved. It&#x27;s literally: watch, memorize (short term), vomit.&lt;&#x2F;p&gt;
&lt;p&gt;And afterwards there is some sense of accomplishment: I did do something. It feels great. Until I have to repeat the video, because I didn&#x27;t understand that much.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I&#x27;ve quit video (courses).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;text&quot;&gt;Text&lt;&#x2F;h2&gt;
&lt;p&gt;Sometimes, I think I am the only person who reads hard paper books. So even if I just have the digital book, I print it.&lt;&#x2F;p&gt;
&lt;p&gt;Then I sit down at my desk and use pencil &amp;amp; paper.&lt;&#x2F;p&gt;
&lt;p&gt;Now here is the important part: I do &lt;strong&gt;not&lt;&#x2F;strong&gt; mark the text excessively. Why? Because I don&#x27;t want to read, memorize, vomit.&lt;&#x2F;p&gt;
&lt;p&gt;I want to understand. That&#x27;s why I read a paragraph, try to rephrase it and write it down. I also write down questions about the paragraph.&lt;&#x2F;p&gt;
&lt;p&gt;One of the biggest pros: I actively practice critical thinking. When I have problems to rephrase it, I probably didn&#x27;t understand it. So this is a great feedback loop.&lt;&#x2F;p&gt;
&lt;p&gt;There is one additional big advantage: I can skim over the book to get a first overview of the content and read very selectively. No, I don&#x27;t have to read the whole book. I can&#x27;t bill by hours.&lt;&#x2F;p&gt;
&lt;p&gt;Getting in overview is only possible in video or audio if there are timestamps (most sources don&#x27;t have them).&lt;&#x2F;p&gt;
&lt;p&gt;There is also the idea, that writing with pencil &amp;amp; paper uses the body memory.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;audio&quot;&gt;Audio&lt;&#x2F;h2&gt;
&lt;p&gt;Audio is somewhere in between for me. Probably because I know that it is pretty useless, because I mostly do this while doing other stuff. So there isn&#x27;t this deceptive trap of thinking that I was so productive.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;sources&quot;&gt;Sources&lt;&#x2F;h1&gt;
&lt;h2 id=&quot;blogs&quot;&gt;Blogs&lt;&#x2F;h2&gt;
&lt;p&gt;It&#x27;s simple: The hardest part for me is to find good quality. This is actually a lot of work.&lt;&#x2F;p&gt;
&lt;p&gt;Especially in tech, where the world is turning fast, search engines show a lot of old blog posts and articles. So this creates uncertainty and more work.&lt;&#x2F;p&gt;
&lt;p&gt;Questions to ask:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;JavaScript post from 2016?&lt;&#x2F;li&gt;
&lt;li&gt;Is this still best practice?&lt;&#x2F;li&gt;
&lt;li&gt;Has something changed?&lt;&#x2F;li&gt;
&lt;li&gt;How can I find out?&lt;&#x2F;li&gt;
&lt;li&gt;Is the content even correct?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This leads to the next source.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-creator&quot;&gt;The Creator&lt;&#x2F;h2&gt;
&lt;p&gt;This is a big one and I think beginners do this far too rarely.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s say I want to understand React, what could probably be the most reliably and correct source? Yes, the creator of React - Facebook and their &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;reactjs.org&#x2F;&quot;&gt;React Docs&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The creator of something is probably the most reliable source for the history of stuff. And if I know the history and &lt;strong&gt;why&lt;&#x2F;strong&gt; something was created, I can think more critically about it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;neutral-source-wikipedia-stack-overflow-etc&quot;&gt;Neutral Source (Wikipedia, Stack Overflow etc.)&lt;&#x2F;h2&gt;
&lt;p&gt;I go to Wikipedia when I&#x27;m really new to a topic. I skim over the page, especially the Table of Content to get a good grasp of what this is.&lt;&#x2F;p&gt;
&lt;p&gt;I try to connect it to my existing knowledge and guess how this could fit in.&lt;&#x2F;p&gt;
&lt;p&gt;But I&#x27;m always very critical, because some editors get paid, especially in the business world.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;tl-dr&quot;&gt;TL;DR&lt;&#x2F;h1&gt;
&lt;p&gt;As you can see, for me it&#x27;s a lot &lt;strong&gt;about probabilities&lt;&#x2F;strong&gt;. Are there awesome blog posts? Sure. Are there shitty docs? Yes!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Formats&lt;&#x2F;strong&gt;: I read text in the form of hard paper books. If there are no books, I at least print it, even some programming docs. I rarely use audio or video.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Sources&lt;&#x2F;strong&gt;: I first check the Wikipedia page to get an overview, then I hit the creator&#x27;s page to understand the concepts and whys. If I have some questions, I search them on the Github Issues or Stack Overflow.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h1 id=&quot;interesting-questions&quot;&gt;Interesting Questions&lt;&#x2F;h1&gt;
&lt;ul&gt;
&lt;li&gt;How do you approach your learning?&lt;&#x2F;li&gt;
&lt;li&gt;Do you even think about it?&lt;&#x2F;li&gt;
&lt;li&gt;What are your pros and cons?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>When to write a blog post</title>
        <published>2021-01-24T00:00:00+00:00</published>
        <updated>2021-01-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2021-01-24/" type="text/html"/>
        <id>https://miku86.com/2021-01-24/</id>
        
        <content type="html">&lt;p&gt;Swyx published an interesting post about &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.swyx.io&#x2F;three-strikes&#x2F;&quot;&gt;his Three Strikes Rule&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m struggling with this a lot.&lt;&#x2F;p&gt;
&lt;p&gt;My flow of thoughts is mostly like this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;quot;Oh cool, I should write about this!&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;Hmm, it should meet my minimum requirements, e.g. backed by science.&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;Grr, it&#x27;s complex. I should do more research.&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;Wow, this should become a whole series. Or a web page.&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;3 weeks later: &amp;quot;I had a lot of other stuff to do, maybe I should trash it.&amp;quot;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So it boils down to high requirements, high complexity and procrastination.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;iprocrastinate.libsyn.com&#x2F;&quot;&gt;Dr. Pychyl&lt;&#x2F;a&gt; emphasizes the importance of concrete and tiny.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I will change my approach and streamline it:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;When I read something interesting or create a new idea, I will add it to my notes app (just in the title).&lt;&#x2F;li&gt;
&lt;li&gt;When I talk about it again (e.g. with a friend), I will add the details into the note of step 1.&lt;&#x2F;li&gt;
&lt;li&gt;When I talk about it the next time, I will add [Publish] in front of the note.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;We will see how this goes!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Thoughts about Daily Diary</title>
        <published>2020-11-18T00:00:00+00:00</published>
        <updated>2020-11-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-18/" type="text/html"/>
        <id>https://miku86.com/2020-11-18/</id>
        
        <content type="html">&lt;p&gt;This is meta.&lt;&#x2F;p&gt;
&lt;p&gt;On dev.to I have 12.700 followers. Since starting the daily diary, the number &lt;em&gt;decreased&lt;&#x2F;em&gt;.
Each post has some 30-50 visits.&lt;&#x2F;p&gt;
&lt;p&gt;Looking at this, I ask myself some questions:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Should I care?&lt;&#x2F;li&gt;
&lt;li&gt;Is the content &amp;quot;useful&amp;quot; or &amp;quot;useless&amp;quot;? Does it matter?&lt;&#x2F;li&gt;
&lt;li&gt;Do people care more about my old stuff, mostly tiny tutorials? Is this something I want to contribute to - &amp;quot;tutorial hell&amp;quot;?&lt;&#x2F;li&gt;
&lt;li&gt;Is the habit more valuable than the actual content?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;A lot of questions.&lt;&#x2F;p&gt;
&lt;p&gt;To answer them, I need to get in contact with my core values. Why do I even write this daily diary?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Big Debugging Session, JS Workshop</title>
        <published>2020-11-17T00:00:00+00:00</published>
        <updated>2020-11-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-17/" type="text/html"/>
        <id>https://miku86.com/2020-11-17/</id>
        
        <content type="html">&lt;p&gt;I worked for some solid 4hrs on the course platform. Most of the stuff was debugging, because literally everything crashed. The debugging tasks are getting easier, because I learn the tools and created some aliases, mostly for the long Docker commands.&lt;&#x2F;p&gt;
&lt;p&gt;In the evening I hosted a JavaScript workshop. Our app is evolving and the folks&#x27; skills are improving a lot.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Course Platform, Workout Habit</title>
        <published>2020-11-16T00:00:00+00:00</published>
        <updated>2020-11-16T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-16/" type="text/html"/>
        <id>https://miku86.com/2020-11-16/</id>
        
        <content type="html">&lt;p&gt;I worked the whole day on my course platform. I added a first draft of the homepage.&lt;&#x2F;p&gt;
&lt;p&gt;My workout habit is working fine. I do one heavy compound exercises every day to strengthen the habit. I like the everday-approach, so the daily work volume has to be lower than just doing 3 workouts per week.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Backup Progress</title>
        <published>2020-11-15T00:00:00+00:00</published>
        <updated>2020-11-15T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-15/" type="text/html"/>
        <id>https://miku86.com/2020-11-15/</id>
        
        <content type="html">&lt;p&gt;I got my new 64GB USB stick. You can read about my backup story &lt;a href=&quot;&#x2F;blog&#x2F;day-2020-11-06&quot;&gt;here&lt;&#x2F;a&gt; and &lt;a href=&quot;&#x2F;blog&#x2F;day-2020-11-07&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The script is fairly simple:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sh&quot; class=&quot;language-sh &quot;&gt;&lt;code class=&quot;language-sh&quot; data-lang=&quot;sh&quot;&gt;#!&amp;#x2F;bin&amp;#x2F;sh
now=$(date +%Y-%m-%d_%H-%M-%S)
user=miku86
backup_source=&amp;#x2F;home&amp;#x2F;$user
backup_dest_local=&amp;#x2F;home&amp;#x2F;$user&amp;#x2F;BACKUP&amp;#x2F; # do not forget to exclude this
backup_dest_external=&amp;#x2F;run&amp;#x2F;media&amp;#x2F;$user&amp;#x2F;HOMEBACKUP&amp;#x2F;$now

rsync -h --progress --stats -r -tgo -p -l -D --update --delete-after --delete-excluded \
# ... many lines of exluding folders, e.g. cache, node_modules etc.
$backup_source $backup_dest_local &amp;amp;&amp;amp;
cp -r $backup_dest_local $backup_dest_external
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Every some days I move the data from the USB stick to my external long-term backup after some cleaning.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Tech-Free Days</title>
        <published>2020-11-14T00:00:00+00:00</published>
        <updated>2020-11-14T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-14/" type="text/html"/>
        <id>https://miku86.com/2020-11-14/</id>
        
        <content type="html">&lt;p&gt;Because I&#x27;m a lot in-front of technical devices, this was my first tech-free day this year. I didn&#x27;t turn on my notebook, although I could have done it. (e.g. not on vacation without it). At first I wanted to research some ideas literally every 10 minutes. But I wrote down every idea on paper. Every distraction is just one click away, because a lot of different tools live in the same environment (the browser).&lt;&#x2F;p&gt;
&lt;p&gt;Cal Newport asks the question &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.calnewport.com&#x2F;blog&#x2F;2009&#x2F;02&#x2F;04&#x2F;have-we-lost-our-tolerance-for-a-little-boredom&#x2F;&quot;&gt;&amp;quot;Have We Lost Our Tolerance For a Little Boredom?&amp;quot;&lt;&#x2F;a&gt;. So I want to get more bored, starting with more reading sessions, where I just focus on this one thing.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Ranger as File Explorer</title>
        <published>2020-11-13T00:00:00+00:00</published>
        <updated>2020-11-13T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-13/" type="text/html"/>
        <id>https://miku86.com/2020-11-13/</id>
        
        <content type="html">&lt;p&gt;In the morning I translated more stuff.&lt;&#x2F;p&gt;
&lt;p&gt;After lunch I debugged an issue in &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;ranger&#x2F;ranger&quot;&gt;ranger&lt;&#x2F;a&gt;. Ranger is my most favorite file explorer. Awesome to work with it.&lt;&#x2F;p&gt;
&lt;p&gt;In the afternoon I did two mentoring sessions. Mentoring is awesome. Helping people with your knowledge, learning to talk about concepts. All this while getting paid.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Debugging Docker</title>
        <published>2020-11-12T00:00:00+00:00</published>
        <updated>2020-11-12T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-12/" type="text/html"/>
        <id>https://miku86.com/2020-11-12/</id>
        
        <content type="html">&lt;p&gt;Quiet day!&lt;&#x2F;p&gt;
&lt;p&gt;The day started with translating.
No tech stuff, just how to get help as a beginner.
This is a very important topic.&lt;&#x2F;p&gt;
&lt;p&gt;Afternoon was all about finishing the deployment of the backend.
I finally did it. Learned a lot about Docker internals.&lt;&#x2F;p&gt;
&lt;p&gt;Big thanks to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;josegonzalez&quot;&gt;josegonzalez&lt;&#x2F;a&gt;, because he debugs literally every &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dokku&#x2F;dokku&#x2F;issues&quot;&gt;dokku issue&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Docker with Dokku, Not Caring about the Implementation Details</title>
        <published>2020-11-11T00:00:00+00:00</published>
        <updated>2020-11-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-11/" type="text/html"/>
        <id>https://miku86.com/2020-11-11/</id>
        
        <content type="html">&lt;p&gt;Again started the day with some focused 2 hours of translating my JS course, finished the part about arrays.&lt;&#x2F;p&gt;
&lt;p&gt;I then started to finish my backend deployment. My current architecture looks like this:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Hardware: the base is a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;m.do.co&#x2F;c&#x2F;a8e98aece58d&quot;&gt;Digital Ocean Droplet&lt;&#x2F;a&gt; with 1 CPU and 2GB RAM.&lt;&#x2F;li&gt;
&lt;li&gt;Base System: as base image I use the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;marketplace.digitalocean.com&#x2F;apps&#x2F;dokku&quot;&gt;1-click Dokku&lt;&#x2F;a&gt; based on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;ubuntu.com&#x2F;&quot;&gt;Ubuntu&lt;&#x2F;a&gt; that manages the Docker containers.&lt;&#x2F;li&gt;
&lt;li&gt;Services: each of &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nextjs.org&#x2F;&quot;&gt;NextJS&lt;&#x2F;a&gt; (Client), &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.apollographql.com&#x2F;&quot;&gt;Apollo&lt;&#x2F;a&gt; (Server), &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;&quot;&gt;Postgres&lt;&#x2F;a&gt; (Database), &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;redis.io&#x2F;&quot;&gt;Redis&lt;&#x2F;a&gt; (Cache) lives in its own container.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I automated the setup of the services and the deployments with bash scripts, so it&#x27;s easy for me to spin this up again if something breaks or I want to leave Digital Ocean.&lt;&#x2F;p&gt;
&lt;p&gt;I needed the whole afternoon to set this up and most of the stuff is working now. Learned a lot about the internals of Docker. Extremely exciting topic.&lt;&#x2F;p&gt;
&lt;p&gt;This is also about the bigger concepts. I don&#x27;t care about technology X. I use the concepts (e.g. a service lives isolated in its own container) and connect them with the biggest tools (e.g. Docker). I use the biggest tools, because I find more resources when stuck and also more plugins and tools.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;In which topics are you currently most interested?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Arrays in Real Life, History Class, Not A Firefighter</title>
        <published>2020-11-10T00:00:00+00:00</published>
        <updated>2020-11-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-10/" type="text/html"/>
        <id>https://miku86.com/2020-11-10/</id>
        
        <content type="html">&lt;p&gt;Started the day with some focused 2,5 hours of translating my JS course, mostly explaining concepts around arrays, related to real life.&lt;&#x2F;p&gt;
&lt;p&gt;This is an interesting one. I hated history class in high school. Our teacher loved rote review. I always thought it was pointless, because this is not how our brain works. Nowadays I love history. Because history tells how things evolved. We can ask questions like &amp;quot;Why did someone come up with the concept of an array?&amp;quot; and &amp;quot;Is there some concept in real life that works the same?&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;I see beginners often struggle with abstract concepts like arrays. But everyone understands how a shopping list works: There is a piece of paper (storage). You write a new item on the paper (create), or you strike it (delete or done) or you correct it (update). Every 5 year old understands the concept and how to use it. But when we try to learn (programming), we start using flash cards or other rote review concepts. Rote reviewing for the sake of getting good exam grades that ask for good rote reviewing skills you probably never use in real life.&lt;&#x2F;p&gt;
&lt;p&gt;Afterwards did my workout routine and my messenger routine, meaning inbox zero for Whatsapp and Telegram. This is hard for me, because I get a lot of messages. Replying after some weeks feels awkward, so I mostly don&#x27;t keep in touch. But living a lifestyle of always online and being distracted annoys me too. Focus is a super important skill. That&#x27;s why I&#x27;m into Digital Minimalism for many years. I&#x27;m neither a emergency doctor nor a firefighter, so most stuff is not that important.&lt;&#x2F;p&gt;
&lt;p&gt;I did a second smooth translation session in the afternoon and hosted a workshop about JavaScript and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;d3js.org&#x2F;&quot;&gt;D3&lt;&#x2F;a&gt; in the evening.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Digital Minimalism, Analog Hobby</title>
        <published>2020-11-09T00:00:00+00:00</published>
        <updated>2020-11-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-09/" type="text/html"/>
        <id>https://miku86.com/2020-11-09/</id>
        
        <content type="html">&lt;p&gt;I worked on translating lessons of my JS course. It&#x27;s actually hard to write explanations for non-techies. Mostly I&#x27;m like &amp;quot;Does the reader know what this term means?&amp;quot; (e.g. &amp;quot;Browser&amp;quot;, &amp;quot;Chrome&amp;quot;, &amp;quot;Explorer&amp;quot;)&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Afterwards I read on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;digitalminimalism&#x2F;wiki&#x2F;index&quot;&gt;Digital Minimalism&lt;&#x2F;a&gt;. I don&#x27;t use Social Media that much. Quit my Facebook some years ago. Not interested in Instagram (hardcore fake stuff). Reddit is cool for reading other peoples&#x27; ideas. Twitter is nice to publish stuff. That&#x27;s it. One (secondary) quote from Cal Newport has stuck in my head: Create the skill of thinking for yourself instead of relying on other peoples&#x27; opinions. If you understand the concepts behind something, you can create the next steps on your own. Sure, always check if they are right or wrong. Be open for new ideas. &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.swyx.io&#x2F;first-principles-approach&#x2F;&quot;&gt;Swyx has a good article about this&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;I try to add a new analog hobby to my life. Most days I&#x27;m in front of my laptop, mostly 12 hours. That&#x27;s why I added reading to my life. Like sitting on a chair, reading stuff on paper and using a pencil. If ideas come into my mind, I write them in a self-made paper notebook (some clamped paper pieces). This removes the urge to immediately run to the laptop&#x2F;smartphone. Nothing gets lost.&lt;&#x2F;p&gt;
&lt;p&gt;What are your analog hobbies?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>USB stick instead of cloud, refurbish old notebook</title>
        <published>2020-11-08T00:00:00+00:00</published>
        <updated>2020-11-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-08/" type="text/html"/>
        <id>https://miku86.com/2020-11-08/</id>
        
        <content type="html">&lt;p&gt;I ditched the plan of sending my backups to the cloud. I wrote an old school script to send it via FTP and my speed was around 10Mbit&#x2F;s, the upper limit of my contract. Could update it to 40Mbit&#x2F;s, but even then 10GB would need 35min to send.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I ordered a small USB stick (Samsung FIT Plus 64GB). Benchmarks showed 60MB&#x2F;s (= 480Mbit&#x2F;s), leading to 3 minutes for 10GB of data. Once per week I will move the data to my external hard drive and clear the stick. I think that&#x27;s a viable approach.&lt;&#x2F;p&gt;
&lt;p&gt;Afterwards I tried to refurbish an old notebook. An old two core 32bit CPU with 2GB RAM, so no need to trash it, I will give it away, maybe to a school or a youth center. But first I had to check if it is too slow. I installed &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.debian.org&#x2F;CD&#x2F;netinst&#x2F;&quot;&gt;Debian&lt;&#x2F;a&gt; without a desktop environment and added &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;i3wm.org&#x2F;&quot;&gt;i3&lt;&#x2F;a&gt;. Will do further investigations, e.g. how well Libre Office and a small browser will perform. If this won&#x27;t run, it&#x27;s probably too slow. That would be sad, because the notebook has been well maintained.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Firefox for Privacy, Backup with Rsync and 7Zip, Soccer</title>
        <published>2020-11-07T00:00:00+00:00</published>
        <updated>2020-11-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-07/" type="text/html"/>
        <id>https://miku86.com/2020-11-07/</id>
        
        <content type="html">&lt;p&gt;I worked on my JS course for 2 hours, rewriting a lot of stuff, making it really simple.&lt;&#x2F;p&gt;
&lt;p&gt;Afterwards I had to tackle a big task: reinstalling Firefox. Actually ditching Firefox Developer Edition, because updating (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;archlinux&#x2F;svntogit-community&#x2F;commits&#x2F;packages&#x2F;firefox-developer-edition&#x2F;trunk&quot;&gt;11 times last month&lt;&#x2F;a&gt;) is very annoying and sometimes stuff breaks. The default Firefox package had only &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;archlinux&#x2F;svntogit-packages&#x2F;commits&#x2F;packages&#x2F;firefox&#x2F;trunk&quot;&gt;3 updates last month&lt;&#x2F;a&gt; and is just one version behind, that&#x27;s okay.&lt;&#x2F;p&gt;
&lt;p&gt;Then I hardened my Firefox to be more privacy focused. Here you can see my &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;miku86&#x2F;dotfiles&#x2F;tree&#x2F;master&#x2F;firefox&quot;&gt;privacy settings and extensions&lt;&#x2F;a&gt;. Keeping up with the newest privacy settings is hard. From now on I just wait for new discoveries on reddit.&lt;&#x2F;p&gt;
&lt;p&gt;I also refined my new backup approach. I&#x27;ve written a simple &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;wiki.archlinux.org&#x2F;index.php&#x2F;Rsync&quot;&gt;rsync&lt;&#x2F;a&gt; script that creates a backup folder. Then I compress and encrypt the folder with 7zip. Duration is around 10 minutes. Next step is to send it to my cloud storage. Alex had the great idea to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;alxtrnr&#x2F;comment&#x2F;17kma&quot;&gt;use an USB stick&lt;&#x2F;a&gt; and I will add this to my approach, because sending 10GB-20GB over the wire is slow. I will also have a look at buying a SD card, so I will probably send it to my Raspberry Pi.&lt;&#x2F;p&gt;
&lt;p&gt;In the evening I watched some soccer for leisure.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>My new backup approach</title>
        <published>2020-11-06T00:00:00+00:00</published>
        <updated>2020-11-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-06/" type="text/html"/>
        <id>https://miku86.com/2020-11-06/</id>
        
        <content type="html">&lt;p&gt;I did two mentoring sessions in the morning, talking about life, some MongoDB details and Cypress testing. Love the mentoring setting, it&#x27;s really open-minded and most mentees are professionals in other fields (finance, engineering).&lt;&#x2F;p&gt;
&lt;p&gt;Then I started a 7h stint of rethinking my approach to managing my data. What to do if my device breaks? If we don&#x27;t have backups, the data is lost. That&#x27;s why we create backups (I hope you do!).&lt;&#x2F;p&gt;
&lt;p&gt;My approach is at least &amp;quot;fragile&amp;quot;. After every boot my &lt;code&gt;home&lt;&#x2F;code&gt; directory gets backup-ed into a directory outside my &lt;code&gt;home&lt;&#x2F;code&gt; directory. That&#x27;s fragile; if the drive dies, the backup is also gone. That&#x27;s why I move the folder &lt;em&gt;manually&lt;&#x2F;em&gt; on an external drive. The time between creating and moving it to the external drive is a weak spot. The bigger the gap, the higher the probability to lose data. Currently my gap is embarrassingly high, probably 30 days. But I don&#x27;t want to plug in my external drive all the time. That&#x27;s why my plan is to put it online. But yes, private data in the cloud, I know... that&#x27;s why I will encrypt it locally.&lt;&#x2F;p&gt;
&lt;p&gt;So my first sketch looks like this:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;&amp;#x2F;home
|--&amp;gt; external drive (daily, unencrypted (simple to access, someone would have to break into my house))
|--&amp;gt; cloud (daily, encrypted (you don&amp;#x27;t get my data))
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;All this should be as app-agnostic as possible and FOSS. I&#x27;m very data minimalistic, meaning I only own 20GB of data. Current problems are the slow encryption (30 minutes with 7z with a i7 CPU). Uploading 20GB of data with 25mbit&#x2F;s needs like 2 hours. So incremental backups are probably a better solution. My next step is to find a simple solution I can automate with a bash script. I will have a look into &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;borgbackup&#x2F;borg&quot;&gt;Borg&lt;&#x2F;a&gt; and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;rclone&#x2F;rclone&quot;&gt;Rclone&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>&#x27;Would my Grandma understand this?&#x27;, Self-criticism vs. Self-compassion, Reading</title>
        <published>2020-11-05T00:00:00+00:00</published>
        <updated>2020-11-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-05/" type="text/html"/>
        <id>https://miku86.com/2020-11-05/</id>
        
        <content type="html">&lt;p&gt;I worked on my JS course, especially the chapter about booleans and loops. Writing this for non-techies and non-native speakers needs a lot of attention and effort. Writing for techies is easier for me, because I can formulate like I think. Formulating for non-techies adds the additional step of translating from my thinking. My simplest feedback question is &amp;quot;Would my grandma understand this?&amp;quot;. I visualize myself talking to her about this stuff. &amp;quot;Hey grandma, so the lightbulb in your kitchen is either turned on or turned off. There is no other state. Either on or off. &lt;em&gt;click&lt;&#x2F;em&gt;&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;The rest of the day was taking a rest. I learned this the last few months. It&#x27;s important to take rests. There is no need to feel guilty or even ashamed if you need a rest. I try to avoid &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Self-criticism&quot;&gt;Self-critisism&lt;&#x2F;a&gt; and use &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Self-compassion&quot;&gt;Self-compassion&lt;&#x2F;a&gt;. It&#x27;s a very interesting topic, I recommend to read up on it.&lt;&#x2F;p&gt;
&lt;p&gt;In the evening I did my tiny workout routine, answered all messages and continued on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.lesswrong.com&#x2F;s&#x2F;5g5TkQTe9rmPS5vvM&quot;&gt;Rationality: A-Z&lt;&#x2F;a&gt;. I learned most of this stuff in university, so it&#x27;s a quick refresher.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>US Election, All or Nothing, KISS</title>
        <published>2020-11-04T00:00:00+00:00</published>
        <updated>2020-11-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-04/" type="text/html"/>
        <id>https://miku86.com/2020-11-04/</id>
        
        <content type="html">&lt;p&gt;Although I am not that much into politics, I love numbers and data. I invested some hours to watch the newest data on the US election.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s an interesting realization. When my morning is &amp;quot;chaotic&amp;quot; meaning I discard my normal schedule, the rest of the day will be the same. Some &amp;quot;all or nothing&amp;quot;-mindset I think. I need to look into this.&lt;&#x2F;p&gt;
&lt;p&gt;Several hours later I started to work on my JS course. I&#x27;m nearly done with the first path - we&#x27;ll build a simple application for the browser console, because you don&#x27;t have to install NodeJS or something else. Keep it simple, stupid.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Existing Knowledge, Meta Skills, Student Progress</title>
        <published>2020-11-03T00:00:00+00:00</published>
        <updated>2020-11-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-03/" type="text/html"/>
        <id>https://miku86.com/2020-11-03/</id>
        
        <content type="html">&lt;p&gt;Busy, monotonous day. I worked on my JavaScript course. I try to explain the concepts with a lot of everyday concepts. I think this is one of the best approaches to learning: learning the fundamental concepts by connecting new information with existing personal knowledge. Every person has existing knowledge so I want to use it.&lt;&#x2F;p&gt;
&lt;p&gt;This is also about meta skills, e.g. focusing, reading, logical thinking etc. When working with beginners, like 95% of the problems come from:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;focusing: students don&#x27;t work focused, so they make typos&lt;&#x2F;li&gt;
&lt;li&gt;reading: students don&#x27;t read error messages or documentations&lt;&#x2F;li&gt;
&lt;li&gt;logical thinking: students throw syntax they already know at the problem, watching what sticks - instead of thinking in &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Pseudocode&quot;&gt;pseudo code&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;In the evening I hosted a workshop on JavaScript. We created a small shopping list from scratch. I did this with exactly the same students some months ago, this time we just needed 1h instead of ~10h. Seems they are making some progress.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Docker Fundamentals, JS Course, Contemplation</title>
        <published>2020-11-02T00:00:00+00:00</published>
        <updated>2020-11-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-02/" type="text/html"/>
        <id>https://miku86.com/2020-11-02/</id>
        
        <content type="html">&lt;p&gt;My first task was to move some parts of my local dev environment into containers. I did this for Postgres, PGAdmin and Redis. Re-learned a lot about Docker. The &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.docker.com&#x2F;resources&#x2F;what-container&quot;&gt;fundamentals&lt;&#x2F;a&gt; are actually quite simple. The container terminology comes from the cargo&#x2F;shipping industry. As a cargo manager, you don&#x27;t have to deal with different cargo sizes placed onto the ship, the people who want to ship their stuff just put them in standardized containers. The cargo manager now just has to keep track of the amount of containers, instead of how to place them tetris-like onto the ship.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;instruction set (= Dockerfile) =&amp;gt; image from the instruction set =&amp;gt; container instance from the image&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If you want to use a pre-made image, you can download it from &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hub.docker.com&#x2F;search?q=&amp;amp;type=image&quot;&gt;Docker Hub&lt;&#x2F;a&gt; and skip creating your own instruction set.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Afterwards I worked on the content of my JavaScript course. I think I use a cool approach. Less about the nitty-gritty implementation details (= what to type), more about how to think. I think beginners care too much about the implementation details (&amp;quot;Which programming style&#x2F;language&#x2F;framework&#x2F;syntax should I use?&amp;quot;).&lt;&#x2F;p&gt;
&lt;p&gt;First beta release to get first feedback is planned for end of next week.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;In the afternoon I did a big printing session. I like do work on my contemplation stuff with pen &amp;amp; paper. I think it is important to have analog skill hobbies. I think even social activities nowadays have a high amount of screen time. That&#x27;s why I read &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.lesswrong.com&#x2F;rationality&quot;&gt;Rationality: A-Z&lt;&#x2F;a&gt;. Focused reading at a desk is highly underrated.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Linux VMs, RedwoodJS, Show Up, Nextcloud Backup</title>
        <published>2020-11-01T00:00:00+00:00</published>
        <updated>2020-11-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-11-01/" type="text/html"/>
        <id>https://miku86.com/2020-11-01/</id>
        
        <content type="html">&lt;p&gt;Did a lot of computer housekeeping. Downloaded some virtual machine images from &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.linuxvmimages.com&quot;&gt;linuxvmimages.com&lt;&#x2F;a&gt;. Downloading a VM image is faster for me than downloading an iso and installing it, so I tinkered around with some. Although I use Arch for some years now, I like the spin of Manjaro. The default settings are great. No doubt linux beginners like it. Was quite fast in a VM with 2 cores and 4GB RAM.&lt;&#x2F;p&gt;
&lt;p&gt;I actually had the idea to spin up the VMs because I wanted to test &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;redwoodjs.com&quot;&gt;RedwoodJS&lt;&#x2F;a&gt;. I sandbox my applications with &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;netblue30&#x2F;firejail&quot;&gt;Firejail&lt;&#x2F;a&gt;, so I had a lot of trouble trying to run Redwood, because I don&#x27;t use a root account in the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;vscodium.com&quot;&gt;VSCodium&lt;&#x2F;a&gt; terminal.&lt;&#x2F;p&gt;
&lt;p&gt;Afterwards I did my workout routine. It&#x27;s sprinting and pullups. Yes, no bro stuff. Just practicing the habit of showing up.&lt;&#x2F;p&gt;
&lt;p&gt;In the afternoon I tried to find out the best way to make a Nextcloud Backup. Currently I use a built-in app, but it puts the backup on the same device and I think this is very fragile if the device (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;m.do.co&#x2F;c&#x2F;a8e98aece58d&quot;&gt;a Digital Ocean VPS&#x2F;Droplet&lt;&#x2F;a&gt;) dies.&lt;&#x2F;p&gt;
&lt;p&gt;Evening was some mindless &amp;quot;smartphone-reading-while-watching-football&amp;quot;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Filter on Blog, Course Outline</title>
        <published>2020-10-31T00:00:00+00:00</published>
        <updated>2020-10-31T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-31/" type="text/html"/>
        <id>https://miku86.com/2020-10-31/</id>
        
        <content type="html">&lt;p&gt;I added a filter to my blog. You now can see filter between all post, the daily diaries and the tutorials. Different people want to read different stuff :)&lt;&#x2F;p&gt;
&lt;p&gt;Afterwards I started a new workout routine. &amp;quot;Routine&amp;quot; is an exaggerated term. The new routine is showing up daily. Literally doing nothing. Just pro-actively going there.&lt;&#x2F;p&gt;
&lt;p&gt;After lunch I had a look at other JavaScript courses and how they are outlined. My target users are beginners - real beginners. So no &amp;quot;math graduate&amp;quot;-type beginners. That&#x27;s why my most important benchmark will be simplicity.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Better Speaking Skills</title>
        <published>2020-10-30T00:00:00+00:00</published>
        <updated>2020-10-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-30/" type="text/html"/>
        <id>https://miku86.com/2020-10-30/</id>
        
        <content type="html">&lt;p&gt;The day started with a mentoring call in the morning. It&#x27;s always very insightful, I also learn a lot about other cultures. Feels like my english skills improved a lot. I learned a lot of &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;English-language_idioms&quot;&gt;idioms&lt;&#x2F;a&gt; and colloquial language so far. Stuff I probably never learned in school.&lt;&#x2F;p&gt;
&lt;p&gt;In the afternoon I researched how other high quality JavaScript courses outline their course and how to improve them.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Other Stuff, Mastermind Call</title>
        <published>2020-10-29T00:00:00+00:00</published>
        <updated>2020-10-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-29/" type="text/html"/>
        <id>https://miku86.com/2020-10-29/</id>
        
        <content type="html">&lt;p&gt;Leisure day. I cleared out tasks from my &amp;quot;Other Stuff&amp;quot;-list. This is stuff I want to have a look into (tech) or goal unrelated reads.&lt;&#x2F;p&gt;
&lt;p&gt;In the afternoon I had a mastermind call where we talked about some interesting stuff, e.g. differences between our genders.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>GraphQL hassle, Wheat</title>
        <published>2020-10-28T00:00:00+00:00</published>
        <updated>2020-10-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-28/" type="text/html"/>
        <id>https://miku86.com/2020-10-28/</id>
        
        <content type="html">&lt;p&gt;Long work day. Started with some easy tasks for the course platform, then some other ones.&lt;&#x2F;p&gt;
&lt;p&gt;Did also some mentoring.&lt;&#x2F;p&gt;
&lt;p&gt;Watched a friend doing some pair programming (never did that myself).&lt;&#x2F;p&gt;
&lt;p&gt;Ended the day with 4h of debugging a graphql backend. Will ditch this for now, because the stuff works, just the graphql playground sends me an error.&lt;&#x2F;p&gt;
&lt;p&gt;I also have to do some research on some foods. Seems I&#x27;m allergic against something that gives me gut problems. Thinking about wheat, because I see some correlations between eating wheat flour and having these problems. Correlation? Causation? I don&#x27;t know yet.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Connect Macro and Micro</title>
        <published>2020-10-27T00:00:00+00:00</published>
        <updated>2020-10-27T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-27/" type="text/html"/>
        <id>https://miku86.com/2020-10-27/</id>
        
        <content type="html">&lt;p&gt;My new work routine is great. Most tasks more purposeful, I think because I don&#x27;t lose the connection to the bigger project&#x2F;vision.&lt;&#x2F;p&gt;
&lt;p&gt;2 times 3 hours of real deep work. Coding felt very easy, but driven. Not the normal flow thing were you feel being productive, but you mostly do the unimportant stuff.&lt;&#x2F;p&gt;
&lt;p&gt;Had some gut issues later the day, I will observe my grain intake more closely.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>New Work Routine</title>
        <published>2020-10-26T00:00:00+00:00</published>
        <updated>2020-10-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-26/" type="text/html"/>
        <id>https://miku86.com/2020-10-26/</id>
        
        <content type="html">&lt;p&gt;My first day of using my new daily work routine. I&#x27;m very inspired by Cal Newport. I read his stuff since ~2010 and I like his scientific approach. Deep work was actually never a problem for me.&lt;&#x2F;p&gt;
&lt;p&gt;My new setup looks like this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Life: Vision: Why do I do this? Tool: Joplin&lt;&#x2F;li&gt;
&lt;li&gt;Quarter: Project: What leads to my life goals? Tool: Joplin&lt;&#x2F;li&gt;
&lt;li&gt;Month: Sub-Project: What leads to my quarterly goals? Tool: Nextcloud Deck&lt;&#x2F;li&gt;
&lt;li&gt;Week: Habits&#x2F;Actions: What leads to my monthly goals? Tool: Nextcloud Deck + NextCloud Calendar&lt;&#x2F;li&gt;
&lt;li&gt;Day: Timeboxing Actions: What do I have to do today? Tool: Nextcloud Deck + Nextcloud Calendar + Paper&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Every morning I have a look into my schedule - if there are any appointments. I try to minimize the amount of appointments. Now I know the timeboxes for my deep work, e.g. from 9-12 and 13-16 o&#x27;clock. Then I just go into my Nextcloud Deck, take the most important tasks and put them into the timeboxes. After my first timebox, right in front of my siesta, I revise the schedule, sometimes I have to adjust some tasks. I do this daily planning on paper to always have the daily plan in front of me (closing the calendar browser tab is to easy). After I finished a task I put the Nextcloud Deck Card into &lt;code&gt;Done&lt;&#x2F;code&gt; and add an entry in my Nextcloud Calendar for the sake of reviewing it later (and to write these blog posts).&lt;&#x2F;p&gt;
&lt;p&gt;So this seems to be a lot of planning and tools. But: In the past, I often lost either the macro goals (Why do I do this?) or the micro goals (What do I have to do today?). When I worked in a normal work environment, I mostly felt overwhelmed by all the &amp;quot;urgent&amp;quot; stuff, living in the inbox and the messengers. At the end of the day I was always very tired and frustrated, because I actually was just plumbing broken pipes.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Habit Overhaul, Quitting Disroot</title>
        <published>2020-10-25T00:00:00+00:00</published>
        <updated>2020-10-25T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-25/" type="text/html"/>
        <id>https://miku86.com/2020-10-25/</id>
        
        <content type="html">&lt;p&gt;I had a closer look at my current habits. I quit my morning workout routine lately, because I procrastinated a lot. I did the routine, but often I needed 90-120 minutes from wake up to workout. So I ditched it, going directly to work now. This mostly needs some 15-30 minutes. The biggest challenge for now is to integrate my workout routine in the day. I literally hate it.&lt;&#x2F;p&gt;
&lt;p&gt;Some months ago, I migrated from Google to disroot. I like disroot very much. It&#x27;s a Nextcloud instance managed by some noble folks (I think so).&lt;&#x2F;p&gt;
&lt;p&gt;But there are two major challenges I faced so far:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Because they manage the Nextcloud instance, in the end they decide which features&#x2F;app run on the instance; I love to have my customized platform and I love to learn new stuff; so probably I&#x27;m the wrong user (it&#x27;s free, so I don&#x27;t want to call myself a customer)&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;The web client calendar seems to be very slow for me, so quickly moving tasks on my calendar leads to conflicts; using alternative clients (Lightning, Evolution) didn&#x27;t work out, because I don&#x27;t like their UX&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;That&#x27;s why I started to setup my own, private Nextcloud instance some days ago. I run it in a VPS with Docker. It&#x27;s way faster, probably because I&#x27;m the only user.&lt;&#x2F;p&gt;
&lt;p&gt;So if you want to use Nextcloud, I recommend to use disroot. Also think about donating some money, because free services that don&#x27;t sell your data probably don&#x27;t last that long. One of my goals is to donate some 4-figures to them so that they can keep up their journey. Also non-techies should have the opportunity to get in touch with free open source software like Nextcloud instead of selling their data to big companies.&lt;&#x2F;p&gt;
&lt;p&gt;If you are a tinkerer like me, you could also try to setup your own one. But be aware that you also have to manage it on your own.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Chores</title>
        <published>2020-10-24T00:00:00+00:00</published>
        <updated>2020-10-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-24/" type="text/html"/>
        <id>https://miku86.com/2020-10-24/</id>
        
        <content type="html">&lt;p&gt;I did some chores, sent out some slides, not that much stuff.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Fetcher Function, Cal Newport Podcast</title>
        <published>2020-10-23T00:00:00+00:00</published>
        <updated>2020-10-23T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-23/" type="text/html"/>
        <id>https://miku86.com/2020-10-23/</id>
        
        <content type="html">&lt;p&gt;I added the fetching function into the course platform. Harder than expected. Have to add some testing.&lt;&#x2F;p&gt;
&lt;p&gt;I listened to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.calnewport.com&#x2F;podcast&#x2F;&quot;&gt;Cal Newport&#x27;s podcast&lt;&#x2F;a&gt;. I&#x27;ve found his stuff like 15y ago and read some of his book. Great insights. Nowadays I don&#x27;t consume that much &amp;quot;knowledge&amp;quot;, because it seems to be a lot of procrastination. I am a good single tasker. I don&#x27;t use my phone that much. I don&#x27;t use social media, just two daily Twitter social accountability messages and very rarely replying to someone.&lt;&#x2F;p&gt;
&lt;p&gt;In the evening I did some mentoring. He&#x27;s building a cool platform and will publish it soon, so we talked about branching&#x2F;deployment.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Workshop Prep, Feeling Sick</title>
        <published>2020-10-22T00:00:00+00:00</published>
        <updated>2020-10-22T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-22/" type="text/html"/>
        <id>https://miku86.com/2020-10-22/</id>
        
        <content type="html">&lt;p&gt;I prepared my workshop the whole day, it was the last of 8 sessions. Felt pretty terrible the whole day, so didn&#x27;t work on my course platform.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Call AWS #2, Course Fetcher</title>
        <published>2020-10-21T00:00:00+00:00</published>
        <updated>2020-10-21T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-21/" type="text/html"/>
        <id>https://miku86.com/2020-10-21/</id>
        
        <content type="html">&lt;p&gt;Fixed the broken 2FA&#x2F;MFA on AWS. The support person was very helpful (thanks, Lance). He explained every step very well, why we need to do this and gave me clear instructions what to do next. Great experience.&lt;&#x2F;p&gt;
&lt;p&gt;I then worked on my course platform. I need a possibility to host the course content easily, also with other contributors in mind. My first structure was more complex, but I want it to be simple as possible. I decided to create a folder structure like this:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;course-name&amp;gt;
|-&amp;gt; README.md &amp;#x2F;&amp;#x2F; bigger overview
|-&amp;gt; _settings.js &amp;#x2F;&amp;#x2F; setup title, chapters etc.
|-&amp;gt; draft
|---&amp;gt; lesson01.md
|-&amp;gt; final
|---&amp;gt; lessons
|-----&amp;gt; lesson01.md
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I created a GraphQL query to fetch the data. It was tiring and I needed like 2 hours, but now the job is done and I learned a lot about the GitHub API. The next step is to fetch the data and parse it into useful data.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Call AWS, Platform User Flows</title>
        <published>2020-10-20T00:00:00+00:00</published>
        <updated>2020-10-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-20/" type="text/html"/>
        <id>https://miku86.com/2020-10-20/</id>
        
        <content type="html">&lt;p&gt;My first job was to fix my broken 2FA&#x2F;MFA on AWS. My problem description was ignored and after going back and forth for 2h I gave up. Will continue tomorrow, because I felt angry.&lt;&#x2F;p&gt;
&lt;p&gt;After my big siesta, I worked on my course platform. I added email notifications after signup and signin and created a diagram for my user flows. Then I tackled a big task, thinking about the workflow of a course creator, how the course content flows from the creator&#x27;s mind to the user. I added some small dummy data and I&#x27;m happy for now with the flow.&lt;&#x2F;p&gt;
&lt;p&gt;In the evening I hosted a 1,5h workshop about JavaScript.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Mentoring, Marketing</title>
        <published>2020-10-19T00:00:00+00:00</published>
        <updated>2020-10-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-10-19/" type="text/html"/>
        <id>https://miku86.com/2020-10-19/</id>
        
        <content type="html">&lt;p&gt;Today was a busy day, because I had some appointments. I don&#x27;t like appointments with people, because I have to stop building&#x2F;thinking&#x2F;playing.&lt;&#x2F;p&gt;
&lt;p&gt;My first appointment was some Mentoring and it was great. My mentee is really awesome, I like him and his attitude.&lt;&#x2F;p&gt;
&lt;p&gt;The second appointment was hosting a workshop for web dev beginners. Sometimes participants are actively engaged, sometimes they just are there to consume. Maybe my own expectations are too high and I should adjust my approach.&lt;&#x2F;p&gt;
&lt;p&gt;I asked the mods on a big discord to find some beta users for my course platform and they agreed. Have to write the message and get back to them.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Homogenous Arrays</title>
        <published>2020-08-28T00:00:00+00:00</published>
        <updated>2020-08-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-28/" type="text/html"/>
        <id>https://miku86.com/2020-08-28/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57ef016a7b45ef647a00002d&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;filterHomogenous&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;myArrays&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given an array of arrays, e.g. &lt;code&gt;[[1, 5, 4], [&#x27;a&#x27;, 3, 5], [&#x27;b&#x27;], [], [&#x27;1&#x27;, 2, 3]]&lt;&#x2F;code&gt;,&lt;&#x2F;p&gt;
&lt;p&gt;return a new array which carries over only those arrays from the original which are not empty and whose items are all of the same type,
e.g. &lt;code&gt;[[1, 5, 4], [&#x27;b&#x27;]]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Implicit type casting is not allowed, e.g. &lt;code&gt;[1, &#x27;2&#x27;]&lt;&#x2F;code&gt; would be considered illegal and should be filtered out.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: an array of arrays.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an array of arrays.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise! If we don&#x27;t understand it, we can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Find out if a specific array is not empty&lt;&#x2F;li&gt;
&lt;li&gt;Find out if all elements of a specific array have the same type&lt;&#x2F;li&gt;
&lt;li&gt;Filter the input array for all arrays that pass both&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[[1, 5, 4], [&#x27;a&#x27;, 3, 5], [&#x27;b&#x27;], [], [&#x27;1&#x27;, 2, 3]]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out if array is not empty &amp;amp; if all elements have the same type: &lt;code&gt;[1, 5, 4]&lt;&#x2F;code&gt; =&amp;gt; not empty: &lt;code&gt;true&lt;&#x2F;code&gt;, same type: &lt;code&gt;true&lt;&#x2F;code&gt; =&amp;gt; add to result array: &lt;code&gt;true&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out if array is not empty &amp;amp; if all elements have the same type: &lt;code&gt;[&#x27;a&#x27;, 3, 5]&lt;&#x2F;code&gt; =&amp;gt; not empty: &lt;code&gt;true&lt;&#x2F;code&gt;, same type: &lt;code&gt;false&lt;&#x2F;code&gt; =&amp;gt; add to result array: &lt;code&gt;false&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out if array is not empty &amp;amp; if all elements have the same type: &lt;code&gt;[&#x27;b&#x27;]&lt;&#x2F;code&gt; =&amp;gt; not empty: &lt;code&gt;true&lt;&#x2F;code&gt;, same type: &lt;code&gt;true&lt;&#x2F;code&gt; =&amp;gt; add to result array: &lt;code&gt;true&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out if array is not empty &amp;amp; if all elements have the same type: &lt;code&gt;[]&lt;&#x2F;code&gt; =&amp;gt; not empty: &lt;code&gt;false&lt;&#x2F;code&gt;, same type: &lt;code&gt;true&lt;&#x2F;code&gt; =&amp;gt; add to result array: &lt;code&gt;false&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out if array is not empty &amp;amp; if all elements have the same type: &lt;code&gt;[&#x27;1&#x27;, 2, 3]&lt;&#x2F;code&gt; =&amp;gt; not empty: &lt;code&gt;true&lt;&#x2F;code&gt;, same type: &lt;code&gt;false&lt;&#x2F;code&gt; =&amp;gt; add to result array: &lt;code&gt;false&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Filter the input array for all arrays that pass both: &lt;code&gt;[[1, 5, 4], [&#x27;b&#x27;]]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[[1, 5, 4], [&#x27;b&#x27;]]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function filterHomogenous(myArrays) {
  const isHomogenous = (array) =&amp;gt;
    array.every((el, i, arr) =&amp;gt; typeof el === typeof arr[0]);
  return myArrays.filter((array) =&amp;gt; array.length &amp;amp;&amp;amp; isHomogenous(array));
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log([[1, 5, 4], [&amp;quot;a&amp;quot;, 3, 5], [&amp;quot;b&amp;quot;], [], [&amp;quot;1&amp;quot;, 2, 3]]);
&amp;#x2F;&amp;#x2F; [[1, 5, 4], [&amp;#x27;b&amp;#x27;]] ✅

console.log([[123, 234, 432], [&amp;quot;&amp;quot;, &amp;quot;abc&amp;quot;], [&amp;quot;&amp;quot;], [&amp;quot;&amp;quot;, 1], [&amp;quot;&amp;quot;, &amp;quot;1&amp;quot;], []]);
&amp;#x2F;&amp;#x2F; [[123, 234, 432], [&amp;#x27;&amp;#x27;, &amp;#x27;abc&amp;#x27;], [&amp;#x27;&amp;#x27;], [&amp;#x27;&amp;#x27;, &amp;#x27;1&amp;#x27;]] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-homogenous-arrays&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;every&lt;&#x2F;code&gt; and &lt;code&gt;filter&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;every&quot;&gt;every&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Seconds To Minutes And Hours</title>
        <published>2020-08-27T00:00:00+00:00</published>
        <updated>2020-08-27T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-27/" type="text/html"/>
        <id>https://miku86.com/2020-08-27/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5865cff66b5699883f0001aa&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;toMinutesAndHours&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;seconds&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a number, e.g. &lt;code&gt;3601&lt;&#x2F;code&gt;,
return a string describing how many hours and minutes comprise that many seconds, any remaining seconds left over are ignored,
e.g. &lt;code&gt;1 hour(s) and 0 minute(s)&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a number.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise! If we don&#x27;t understand it, we can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Find out how many full minutes you get from the seconds&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many full hours you get from the minutes and remove them from minutes&lt;&#x2F;li&gt;
&lt;li&gt;Return the string with hours and minutes&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;3601&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many full minutes you get from the seconds: &lt;code&gt;60&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many full hours you get from the minutes and remove them from minutes: &lt;code&gt;1&lt;&#x2F;code&gt; hours and &lt;code&gt;0&lt;&#x2F;code&gt; minutes&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;1 hour(s) and 0 minute(s)&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-while&quot;&gt;Implementation (while) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function toMinutesAndHours() {
  const S_IN_M = 60;
  const M_IN_H = 60;
  let minutes = 0;

  while (seconds - S_IN_M &amp;gt;= 0) {
    minutes++;
    seconds -= S_IN_M;
  }

  let hours = 0;

  while (minutes - M_IN_H &amp;gt;= 0) {
    hours++;
    minutes -= M_IN_H;
  }

  return `${hours} hour(s) and ${minutes} minute(s)`;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(toMinutesAndHours(3600));
&amp;#x2F;&amp;#x2F; &amp;quot;1 hour(s) and 0 minute(s)&amp;quot; ✅

console.log(toMinutesAndHours(3601));
&amp;#x2F;&amp;#x2F; &amp;quot;1 hour(s) and 0 minute(s)&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;implementation-floor&quot;&gt;Implementation (floor) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function toMinutesAndHours() {
  const hours = Math.floor(seconds &amp;#x2F; 3600);
  const minutes = Math.floor((seconds % 3600) &amp;#x2F; 60);

  return `${hours} hour(s) and ${minutes} minute(s)`;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(toMinutesAndHours(3600));
&amp;#x2F;&amp;#x2F; &amp;quot;1 hour(s) and 0 minute(s)&amp;quot; ✅

console.log(toMinutesAndHours(3601));
&amp;#x2F;&amp;#x2F; &amp;quot;1 hour(s) and 0 minute(s)&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-seconds-to-minutes-and-hours&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;while&lt;&#x2F;code&gt;, &lt;code&gt;Math.floor&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;while&quot;&gt;while&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Math&#x2F;floor&quot;&gt;Math.floor&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Letterbox Paint Squad</title>
        <published>2020-08-26T00:00:00+00:00</published>
        <updated>2020-08-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-26/" type="text/html"/>
        <id>https://miku86.com/2020-08-26/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;597d75744f4190857a00008d&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;You and a group of friends are earning some extra money by re-painting the numbers on people&amp;#x27;s letterboxes for a small fee.

Since there are 10 of you in the group, each person just paints one digit, e.g. somebody will paint only the 1&amp;#x27;s, somebody else will paint only the 2&amp;#x27;s and so on...

At the end of the day you realise not everybody did the same amount of work.

To avoid any fights you need to distribute the money fairly. That&amp;#x27;s where this Kata comes in.
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Write a function &lt;code&gt;paintLetterboxes&lt;&#x2F;code&gt;, that accepts two parameter: &lt;code&gt;start&lt;&#x2F;code&gt; and &lt;code&gt;end&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a &lt;code&gt;start&lt;&#x2F;code&gt; number, e.g. &lt;code&gt;125&lt;&#x2F;code&gt;,
and an &lt;code&gt;end&lt;&#x2F;code&gt; number, e.g. &lt;code&gt;132&lt;&#x2F;code&gt;,
return the frequency of all 10 digits painted,
e.g. &lt;code&gt;[1, 9, 6, 3, 0, 1, 1, 1, 1, 1]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;125: 1 x 1, 1 x 2, 1 x 5
126: 1 x 1, 1 x 2, 1 x 6
...
132: 1 x 1, 1 x 3, 1 x 2
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: two numbers.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an array of numbers.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise! If we don&#x27;t understand it, we can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create array with the number of every number between start and end&lt;&#x2F;li&gt;
&lt;li&gt;Map each number into its split digits&lt;&#x2F;li&gt;
&lt;li&gt;Reduce every number into one big array&lt;&#x2F;li&gt;
&lt;li&gt;Create object with all numbers from 0 to 9&lt;&#x2F;li&gt;
&lt;li&gt;Count every digit&lt;&#x2F;li&gt;
&lt;li&gt;Return as array&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;125, 132&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Create array with the number of every number between start and end: &lt;code&gt;[125, 126, 127, 128, 129, 130, 131, 132]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Map each number into its split digits: &lt;code&gt;[ [ &#x27;1&#x27;, &#x27;2&#x27;, &#x27;5&#x27; ], [ &#x27;1&#x27;, &#x27;2&#x27;, &#x27;6&#x27; ], ..., [ &#x27;1&#x27;, &#x27;3&#x27;, &#x27;2&#x27; ] ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Reduce every number into one big array: &lt;code&gt;[ &#x27;1&#x27;, &#x27;2&#x27;, &#x27;5&#x27;, &#x27;1&#x27;, &#x27;2&#x27;, &#x27;6&#x27;, ..., &#x27;1&#x27;, &#x27;3&#x27;, &#x27;2&#x27; ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Create object with all numbers from 0 to 9: &lt;code&gt;{ &#x27;0&#x27;: 0, &#x27;1&#x27;: 0, ... , &#x27;9&#x27;: 0 }&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Count every digit: &lt;code&gt;{ &#x27;0&#x27;: 1, &#x27;1&#x27;: 9, ... , &#x27;9&#x27;: 1 }&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return as array: &lt;code&gt;[ 1, 9, 6, 3, 0, 1, 1, 1, 1, 1 ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[ 1, 9, 6, 3, 0, 1, 1, 1, 1, 1 ]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;🥵&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-explicit&quot;&gt;Implementation (Explicit) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function paintLetterboxes(start, end) {
  &amp;#x2F;&amp;#x2F; create array with the number of every number between start and end
  &amp;#x2F;&amp;#x2F; const array = [...Array(end - start + 1).keys()].map(i =&amp;gt; i + start);
  const allNumbers = [...Array(end + 1).keys()].slice(start);

  &amp;#x2F;&amp;#x2F; map each number into its split digits
  const splitIntoDigits = allNumbers.map((num) =&amp;gt; String(num).split(&amp;quot;&amp;quot;));

  &amp;#x2F;&amp;#x2F; reduce every number into one big array
  &amp;#x2F;&amp;#x2F; const allDigits = splitIntoDigits.reduce((acc, cur) =&amp;gt; acc.concat(cur), []); &amp;#x2F;&amp;#x2F; node &amp;lt; 11
  const allDigits = splitIntoDigits.flat();

  &amp;#x2F;&amp;#x2F; create object with all numbers from 0 to 9
  const startObject = [...Array(10).keys()].reduce(
    (acc, cur) =&amp;gt; ({ ...acc, [cur]: 0 }),
    {}
  );

  &amp;#x2F;&amp;#x2F; count every digit
  const counted = allDigits.reduce(
    (acc, cur) =&amp;gt; ({ ...acc, [cur]: acc[cur] + 1 }),
    startObject
  );

  &amp;#x2F;&amp;#x2F; return as array
  const result = Object.entries(counted).reduce(
    (acc, cur) =&amp;gt; [...acc, cur[1]],
    []
  );

  return result;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(paintLetterboxes(125, 132));
&amp;#x2F;&amp;#x2F; [ 1, 9, 6, 3, 0, 1, 1, 1, 1, 1 ] ✅

console.log(paintLetterboxes(2, 4));
&amp;#x2F;&amp;#x2F; [ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-implicit&quot;&gt;Implementation (Implicit) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function paintLetterboxes(start, end) {
  const startObject = [...Array(10).keys()].reduce(
    (acc, cur) =&amp;gt; ({ ...acc, [cur]: 0 }),
    {}
  );
  const counted = [...Array(end + 1).keys()]
    .slice(start)
    .map((num) =&amp;gt; String(num).split(&amp;quot;&amp;quot;))
    .flat()
    .reduce((acc, cur) =&amp;gt; ({ ...acc, [cur]: acc[cur] + 1 }), startObject);
  return Object.entries(counted).reduce((acc, cur) =&amp;gt; [...acc, cur[1]], []);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(paintLetterboxes(125, 132));
&amp;#x2F;&amp;#x2F; [ 1, 9, 6, 3, 0, 1, 1, 1, 1, 1 ] ✅

console.log(paintLetterboxes(2, 4));
&amp;#x2F;&amp;#x2F; [ 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-letterbox-paint-squad&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;Probably, this solution is way too complicated, but it was fun!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;...&lt;&#x2F;code&gt;, &lt;code&gt;Array&lt;&#x2F;code&gt;, &lt;code&gt;keys&lt;&#x2F;code&gt;, &lt;code&gt;entries&lt;&#x2F;code&gt;, &lt;code&gt;slice&lt;&#x2F;code&gt;, &lt;code&gt;flat&lt;&#x2F;code&gt;, &lt;code&gt;map&lt;&#x2F;code&gt;, &lt;code&gt;reduce&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Spread_syntax&quot;&gt;...&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&quot;&gt;Array&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;keys&quot;&gt;keys&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&#x2F;entries&quot;&gt;entries&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;slice&quot;&gt;slice&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;flat&quot;&gt;flat&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Reduce&quot;&gt;reduce&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Draw Chessboard</title>
        <published>2020-08-25T00:00:00+00:00</published>
        <updated>2020-08-25T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-25/" type="text/html"/>
        <id>https://miku86.com/2020-08-25/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;56242b89689c35449b000059&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;drawChessboard&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;rows&lt;&#x2F;code&gt; and &lt;code&gt;columns&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a &lt;code&gt;rows&lt;&#x2F;code&gt; number, e.g. &lt;code&gt;3&lt;&#x2F;code&gt;, and a &lt;code&gt;columns&lt;&#x2F;code&gt; number, e.g. &lt;code&gt;3&lt;&#x2F;code&gt;,
return a chessboard as a two dimensional array, e.g.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;[
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ],
  [ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ],
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]
]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;White should be represented by &lt;code&gt;&amp;quot;O&amp;quot;&lt;&#x2F;code&gt;, black by &lt;code&gt;&amp;quot;X&amp;quot;&lt;&#x2F;code&gt;, the first row starts with a &lt;code&gt;&amp;quot;O&amp;quot;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: two numbers.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an array of array(s).&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create a row with the correct length (= &lt;code&gt;columns&lt;&#x2F;code&gt;) that starts with &lt;code&gt;&amp;quot;O&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Create a row with the correct length (= &lt;code&gt;columns&lt;&#x2F;code&gt;) that starts with &lt;code&gt;&amp;quot;X&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Do this alternately until there are enough (= &lt;code&gt;rows&lt;&#x2F;code&gt;) rows&lt;&#x2F;li&gt;
&lt;li&gt;Return the array of array(s)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;3, 3&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Create a row with the correct length (= &lt;code&gt;columns&lt;&#x2F;code&gt;) that starts with &lt;code&gt;&amp;quot;O&amp;quot;&lt;&#x2F;code&gt;: &lt;code&gt;[ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Create a row with the correct length (= &lt;code&gt;columns&lt;&#x2F;code&gt;) that starts with &lt;code&gt;&amp;quot;X&amp;quot;&lt;&#x2F;code&gt;: &lt;code&gt;[ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Do this alternately until there are enough (= &lt;code&gt;rows&lt;&#x2F;code&gt;) rows: 1 additional row &lt;code&gt;(=&amp;gt; 3 - 2 = 1)&lt;&#x2F;code&gt; : &lt;code&gt;[ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the array of array(s): &lt;code&gt;[ [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ], [ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ], [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[ [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ], [ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ], [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-explicit&quot;&gt;Implementation (Explicit) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function drawChessboard(rows, columns) {
  &amp;#x2F;&amp;#x2F; Create an empty board with the correct amount of rows
  const board = [...Array(rows)].map((_) =&amp;gt; []);

  &amp;#x2F;&amp;#x2F; Create a row with the correct length that starts with &amp;quot;O&amp;quot;
  const rowO = [...Array(columns)].map((_, i) =&amp;gt; (i % 2 ? &amp;quot;X&amp;quot; : &amp;quot;O&amp;quot;));

  &amp;#x2F;&amp;#x2F; Create a row with the correct length that starts with &amp;quot;X&amp;quot;
  const rowX = [...Array(columns)].map((_, i) =&amp;gt; (i % 2 ? &amp;quot;O&amp;quot; : &amp;quot;X&amp;quot;));

  &amp;#x2F;&amp;#x2F; Add the proper row to each board row
  return board.map((_, i) =&amp;gt; (i % 2 ? rowX : rowO));
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(drawChessboard(3, 3));
&amp;#x2F;*
[
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ],
  [ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ],
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]
]
*&amp;#x2F;
&amp;#x2F;&amp;#x2F; ✅

console.log(drawChessboard(2, 4));
&amp;#x2F;*
[
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ],
  [ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]
]
*&amp;#x2F;
&amp;#x2F;&amp;#x2F;  ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-implicit&quot;&gt;Implementation (Implicit) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function drawChessboard(rows, columns) {
  return [...Array(rows)]
    .map((_) =&amp;gt; [])
    .map((_, i) =&amp;gt;
      i % 2
        ? [...Array(columns)].map((_, i) =&amp;gt; (i % 2 ? &amp;quot;O&amp;quot; : &amp;quot;X&amp;quot;))
        : [...Array(columns)].map((_, i) =&amp;gt; (i % 2 ? &amp;quot;X&amp;quot; : &amp;quot;O&amp;quot;))
    );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(drawChessboard(3, 3));
&amp;#x2F;*
[
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ],
  [ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ],
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]
]
*&amp;#x2F;
&amp;#x2F;&amp;#x2F; ✅

console.log(drawChessboard(2, 4));
&amp;#x2F;*
[
  [ &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot; ],
  [ &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot;, &amp;quot;X&amp;quot;, &amp;quot;O&amp;quot; ]
]
*&amp;#x2F;
&amp;#x2F;&amp;#x2F;  ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-draw-chessboard&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;...&lt;&#x2F;code&gt;, &lt;code&gt;Array&lt;&#x2F;code&gt;, &lt;code&gt;map&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Spread_syntax&quot;&gt;...&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Array&quot;&gt;Array&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Find Odd Digits</title>
        <published>2020-08-21T00:00:00+00:00</published>
        <updated>2020-08-21T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-21/" type="text/html"/>
        <id>https://miku86.com/2020-08-21/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;59e8afdd0863c7bcb300013a&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;findOddDigits&lt;&#x2F;code&gt;, that accepts two parameter: &lt;code&gt;n&lt;&#x2F;code&gt; a number and &lt;code&gt;k&lt;&#x2F;code&gt; a number.&lt;&#x2F;p&gt;
&lt;p&gt;Given &lt;code&gt;n&lt;&#x2F;code&gt;, e.g. &lt;code&gt;123456789111&lt;&#x2F;code&gt;, and &lt;code&gt;k&lt;&#x2F;code&gt;, e.g. &lt;code&gt;5&lt;&#x2F;code&gt;, return the first &lt;code&gt;k&lt;&#x2F;code&gt; odd digits in &lt;code&gt;n&lt;&#x2F;code&gt;, e.g. &lt;code&gt;13579&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In the following cases the function should return &lt;code&gt;0&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;there are no odd digits in &lt;code&gt;n&lt;&#x2F;code&gt;;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;k&lt;&#x2F;code&gt; is bigger than &lt;code&gt;n&lt;&#x2F;code&gt;;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;k&lt;&#x2F;code&gt; is &lt;code&gt;0&lt;&#x2F;code&gt;;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;k&lt;&#x2F;code&gt; is bigger than the number of odd digits in &lt;code&gt;n&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: two numbers.&lt;&#x2F;p&gt;
&lt;p&gt;Output: one number.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Find all odd digits&lt;&#x2F;li&gt;
&lt;li&gt;Find the first &lt;code&gt;k&lt;&#x2F;code&gt; digits&lt;&#x2F;li&gt;
&lt;li&gt;Handle all edge cases&lt;&#x2F;li&gt;
&lt;li&gt;Return the number&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;123456789111, 5&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find all odd digits: &lt;code&gt;13579111&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find the first &lt;code&gt;k&lt;&#x2F;code&gt; (= &lt;code&gt;5&lt;&#x2F;code&gt;) digits: &lt;code&gt;13579&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the number: &lt;code&gt;13579&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;13579&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-explicit&quot;&gt;Implementation (Explicit) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function findOddDigits(n, k) {
  &amp;#x2F;&amp;#x2F; k = 0;
  &amp;#x2F;&amp;#x2F; k is bigger than a number of digits in n;
  if (k === 0 || k &amp;gt; n) return 0;

  &amp;#x2F;&amp;#x2F; find all odd digits
  const str = String(n);
  const split = str.split(&amp;quot;&amp;quot;);
  const odds = split.filter((num) =&amp;gt; num % 2);

  &amp;#x2F;&amp;#x2F; there are no odd digits in a number n;
  &amp;#x2F;&amp;#x2F; k is bigger than a number of odd digits in n.
  if (!odds.length || k &amp;gt; odds.length) return 0;

  &amp;#x2F;&amp;#x2F; find the first `k` digits
  const joined = odds.join(&amp;quot;&amp;quot;);
  const sliced = joined.slice(0, k);

  &amp;#x2F;&amp;#x2F; return the number
  return Number(sliced);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(findOddDigits(123456789111, 5));
&amp;#x2F;&amp;#x2F; 13579 ✅

console.log(findOddDigits(0, 100));
&amp;#x2F;&amp;#x2F; 0 ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-implicit&quot;&gt;Implementation (Implicit) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function findOddDigits(n, k) {
  &amp;#x2F;&amp;#x2F; find all odd digits
  const odds = String(n)
    .split(&amp;quot;&amp;quot;)
    .filter((num) =&amp;gt; num % 2);

  &amp;#x2F;&amp;#x2F; handle all edge cases
  if (k === 0 || k &amp;gt; n || !odds.length || k &amp;gt; odds.length) return 0;

  &amp;#x2F;&amp;#x2F; find the first `k` digits and return them as a number
  return Number(odds.join(&amp;quot;&amp;quot;).slice(0, k));
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(findOddDigits(123456789111, 5));
&amp;#x2F;&amp;#x2F; 13579 ✅

console.log(findOddDigits(0, 100));
&amp;#x2F;&amp;#x2F; 0 ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-find-odd-digits&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;String&lt;&#x2F;code&gt;, &lt;code&gt;Number&lt;&#x2F;code&gt;, &lt;code&gt;split&lt;&#x2F;code&gt;, &lt;code&gt;join&lt;&#x2F;code&gt;, &lt;code&gt;filter&lt;&#x2F;code&gt;, &lt;code&gt;slice&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&quot;&gt;String&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Number&quot;&gt;Number&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;join&quot;&gt;join&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;slice&quot;&gt;slice&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Merge Two Arrays</title>
        <published>2020-08-20T00:00:00+00:00</published>
        <updated>2020-08-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-20/" type="text/html"/>
        <id>https://miku86.com/2020-08-20/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;583af10620dda4da270000c5&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;mergeArrays&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;a&lt;&#x2F;code&gt; and &lt;code&gt;b&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given two arrays, e.g. &lt;code&gt;[9, 10, 11]&lt;&#x2F;code&gt; and &lt;code&gt;[&amp;quot;a&amp;quot;]&lt;&#x2F;code&gt;,
return an array that combines both arrays by alternatingly taking elements from each array in turn, e.g. &lt;code&gt;[9, &amp;quot;a&amp;quot;, 10, 11]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Every element in the arrays is either a string or a number.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: two arrays.&lt;&#x2F;p&gt;
&lt;p&gt;Output: one array.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Take the 1st element of the 1st array&lt;&#x2F;li&gt;
&lt;li&gt;Take the 1st element of the 2nd array&lt;&#x2F;li&gt;
&lt;li&gt;Take the 2nd element of the 1st array&lt;&#x2F;li&gt;
&lt;li&gt;Take the 2nd element of the 2nd array&lt;&#x2F;li&gt;
&lt;li&gt;Do this [length of the longer array] amount times; in JavaScript, you get &lt;code&gt;undefined&lt;&#x2F;code&gt;, if there is no value at a specific index in an array&lt;&#x2F;li&gt;
&lt;li&gt;Filter out every &lt;code&gt;undefined&lt;&#x2F;code&gt; value&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[9, 10, 11], [&amp;quot;a&amp;quot;]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Take the 1st element of the 1st array: &lt;code&gt;9&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Take the 1st element of the 2nd array: &lt;code&gt;&amp;quot;a&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Take the 2nd element of the 1st array: &lt;code&gt;10&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Take the 2nd element of the 2nd array: nothing here =&amp;gt; &lt;code&gt;undefined&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Take the 3rd element of the 1st array: &lt;code&gt;11&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Take the 3rd element of the 2nd array: nothing here =&amp;gt; &lt;code&gt;undefined&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Filter out every &lt;code&gt;undefined&lt;&#x2F;code&gt; value: &lt;code&gt;[9, &amp;quot;a&amp;quot;, 10, 11]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[9, &amp;quot;a&amp;quot;, 10, 11]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function mergeArrays(a, b) {
  const maxLength = Math.max(a.length, b.length);
  let result = [];

  for (let i = 0; i &amp;lt; maxLength; i++) {
    result.push(a[i]);
    result.push(b[i]);
  }

  return result.filter((value) =&amp;gt; value !== undefined);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(mergeArrays([9, 10, 11], [&amp;quot;a&amp;quot;]));
&amp;#x2F;&amp;#x2F; [9, &amp;quot;a&amp;quot;, 10, 11] ✅

console.log(mergeArrays([1], [&amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;]));
&amp;#x2F;&amp;#x2F; [1, &amp;quot;a&amp;quot;, &amp;quot;b&amp;quot;] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-merge-two-arrays&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;Math.max&lt;&#x2F;code&gt;, &lt;code&gt;filter&lt;&#x2F;code&gt;, &lt;code&gt;undefined&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Math&#x2F;max&quot;&gt;Math.max&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;undefined&quot;&gt;undefined&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Higher Version </title>
        <published>2020-08-18T00:00:00+00:00</published>
        <updated>2020-08-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-18/" type="text/html"/>
        <id>https://miku86.com/2020-08-18/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;58884e352ffea6d2f8000082&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;higherVersion&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;version1&lt;&#x2F;code&gt; and &lt;code&gt;version2&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given two strings, e.g. &lt;code&gt;&amp;quot;1.2.3&amp;quot;&lt;&#x2F;code&gt; and &lt;code&gt;&amp;quot;1.2.0&amp;quot;&lt;&#x2F;code&gt;, return if the first string is higher than the second, e.g. &lt;code&gt;true&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;There are no leading zeros, e.g. &lt;code&gt;100.020.003&lt;&#x2F;code&gt; is given as &lt;code&gt;100.20.3&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: two strings.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a boolean.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Check if the current number of the first string is higher, lower or equal than&#x2F;to the first number of the second string&lt;&#x2F;li&gt;
&lt;li&gt;If higher, then return true&lt;&#x2F;li&gt;
&lt;li&gt;If lower, then return false&lt;&#x2F;li&gt;
&lt;li&gt;If equal, go to the next number of both strings and start from step 1&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;1.2.3&amp;quot;, &amp;quot;1.2.0&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Check if the current number of the first string is higher, lower or equal than&#x2F;to the first number of the second string: &lt;code&gt;1&lt;&#x2F;code&gt; and &lt;code&gt;1&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;equal&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;If equal, go to the next number of both strings and start from step 1&lt;&#x2F;li&gt;
&lt;li&gt;Check if the second number of the first string is higher, lower or equal than&#x2F;to the second number of the second string: &lt;code&gt;2&lt;&#x2F;code&gt; and &lt;code&gt;2&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;equal&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;If equal, go to the next number of both strings and start from step 1&lt;&#x2F;li&gt;
&lt;li&gt;Check if the third number of the first string is higher, lower or equal than&#x2F;to the third number of the second string: &lt;code&gt;3&lt;&#x2F;code&gt; and &lt;code&gt;0&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;higher&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;If higher, then return &lt;code&gt;true&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;true&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function higherVersion(version1, version2) {
  &amp;#x2F;&amp;#x2F; split the strings into numbers
  const split1 = version1.split(&amp;quot;.&amp;quot;).map((s) =&amp;gt; Number(s));
  const split2 = version2.split(&amp;quot;.&amp;quot;).map((s) =&amp;gt; Number(s));
  let result = null;

  for (let i = 0; i &amp;lt; split1.length; i++) {
    if (split1[i] &amp;gt; split2[i]) {
      &amp;#x2F;&amp;#x2F; is higher, so break out of the whole loop
      result = true;
      break;
    } else if (split1[i] &amp;lt; split2[i]) {
      &amp;#x2F;&amp;#x2F; is smaller, so break out of the whole loop
      result = false;
      break;
    } else {
      &amp;#x2F;&amp;#x2F; is equal, so check the next number
      result = false;
    }
  }

  return result;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(higherVersion(&amp;quot;1.2.3&amp;quot;, &amp;quot;1.2.0&amp;quot;));
&amp;#x2F;&amp;#x2F; true ✅

console.log(higherVersion(&amp;quot;9&amp;quot;, &amp;quot;10&amp;quot;));
&amp;#x2F;&amp;#x2F; false ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-higher-version&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;split&lt;&#x2F;code&gt;, &lt;code&gt;map&lt;&#x2F;code&gt;, &lt;code&gt;for&lt;&#x2F;code&gt;, &lt;code&gt;break&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for&quot;&gt;for&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;break&quot;&gt;break&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Split In Parts</title>
        <published>2020-08-12T00:00:00+00:00</published>
        <updated>2020-08-12T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-12/" type="text/html"/>
        <id>https://miku86.com/2020-08-12/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5650ab06d11d675371000003&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;splitInParts&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;myString&lt;&#x2F;code&gt; and &lt;code&gt;partLength&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a string, e.g. &lt;code&gt;&amp;quot;HelloDev&amp;quot;&lt;&#x2F;code&gt;,
and a number, e.g. &lt;code&gt;3&lt;&#x2F;code&gt;,
return the input string split into &lt;code&gt;partLength&lt;&#x2F;code&gt;-long parts separated by a space, e.g. &lt;code&gt;Hel loD ev&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string and a number.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Get a &lt;code&gt;partLength&lt;&#x2F;code&gt;-long part of the input string and add a space&lt;&#x2F;li&gt;
&lt;li&gt;Do this for every part&lt;&#x2F;li&gt;
&lt;li&gt;Add the remaining part to the end&lt;&#x2F;li&gt;
&lt;li&gt;Return the string&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;HelloDev&amp;quot;, 3&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Get a &lt;code&gt;3&lt;&#x2F;code&gt;-long part of the input string and add a space: &lt;code&gt;&amp;quot;Hel &amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Get a &lt;code&gt;3&lt;&#x2F;code&gt;-long part of the input string and add a space: &lt;code&gt;&amp;quot;loD &amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Add the remaining part to the end: &lt;code&gt;&amp;quot;ev&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the string: &lt;code&gt;&amp;quot;Hel loD ev&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;Hel loD ev&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function splitInParts(myString, partLength) {
  let remaining = myString;
  let result = &amp;quot;&amp;quot;;

  &amp;#x2F;&amp;#x2F; do it only if the remaining string is longer than the parts
  while (remaining.length &amp;gt;= partLength) {
    &amp;#x2F;&amp;#x2F; add the next part and a space to the result
    result += remaining.slice(0, partLength) + &amp;quot; &amp;quot;;

    &amp;#x2F;&amp;#x2F; remove the added part from the remaining string
    remaining = remaining.slice(partLength);
  }

  &amp;#x2F;&amp;#x2F; add the last part that was smaller than the part length
  result += remaining;

  &amp;#x2F;&amp;#x2F; remove a trailing space
  return result.trim();
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(splitInParts(&amp;quot;HelloDev&amp;quot;, 3));
&amp;#x2F;&amp;#x2F; &amp;quot;Hel loD ev&amp;quot; ✅

console.log(splitInParts(&amp;quot;HelloDev&amp;quot;, 1));
&amp;#x2F;&amp;#x2F; &amp;quot;H e l l o D e v&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-split-in-parts&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;while&lt;&#x2F;code&gt;, &lt;code&gt;slice&lt;&#x2F;code&gt;, &lt;code&gt;trim&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;while&quot;&gt;while&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;slice&quot;&gt;slice&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;trim&quot;&gt;trim&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Coin Combination</title>
        <published>2020-08-11T00:00:00+00:00</published>
        <updated>2020-08-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-11/" type="text/html"/>
        <id>https://miku86.com/2020-08-11/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;564d0490e96393fc5c000029&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;coinCombo&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;cents&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a number of cents, e.g. &lt;code&gt;51&lt;&#x2F;code&gt;,
return the minimum number of coins combination of the same value, e.g. &lt;code&gt;[1, 0, 0, 2]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The function should return an array where:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;coins[0] = 1 cent
coins[1] = 5 cents
coins[2] = 10 cents
coins[3] = 25 cents
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Example: &lt;code&gt;coinCombo(51)&lt;&#x2F;code&gt; needs two &lt;code&gt;25 cents&lt;&#x2F;code&gt; and one &lt;code&gt;1 cent&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;[1, 0, 0, 2]&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a number.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an array of numbers.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Find out how many times I need the 25 cents coin&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many times I need the 10 cents coin&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many times I need the 5 cents coin&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many times I need the 1 cents coin&lt;&#x2F;li&gt;
&lt;li&gt;Return the array with the combination of the coins&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;51&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many times I need the 25 cents coin: &lt;code&gt;2&lt;&#x2F;code&gt;, because &lt;code&gt;2 * 25 = 50&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;1&lt;&#x2F;code&gt; left&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many times I need the 10 cents coin: &lt;code&gt;0&lt;&#x2F;code&gt;, because I got only &lt;code&gt;1&lt;&#x2F;code&gt; left =&amp;gt; &lt;code&gt;1&lt;&#x2F;code&gt; left&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many times I need the 5 cents coin: &lt;code&gt;0&lt;&#x2F;code&gt;, because I got only &lt;code&gt;1&lt;&#x2F;code&gt; left =&amp;gt; &lt;code&gt;1&lt;&#x2F;code&gt; left&lt;&#x2F;li&gt;
&lt;li&gt;Find out how many times I need the 1 cents coin: &lt;code&gt;1&lt;&#x2F;code&gt;, because &lt;code&gt;1 * 1 = 1&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;0&lt;&#x2F;code&gt; left&lt;&#x2F;li&gt;
&lt;li&gt;Return the array with the combination of the coins: &lt;code&gt;[1, 0, 0, 2]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[1, 0, 0, 2]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function coinCombo() {
  &amp;#x2F;&amp;#x2F; all coin values
  const coinValues = [25, 10, 5, 1];

  &amp;#x2F;&amp;#x2F; array for the output, filled with zeros
  const coins = Array(coinValues.length).fill(0);

  let currentCents = cents;

  &amp;#x2F;&amp;#x2F; iterate over the coins
  for (const coin of coinValues) {
    &amp;#x2F;&amp;#x2F; only do this if there are some coins left
    while (currentCents &amp;gt;= coin) {
      &amp;#x2F;&amp;#x2F; find out how many cents are left
      &amp;#x2F;&amp;#x2F; and how many times the current coins fit into the current cents
      const remainder = currentCents % coin;
      const increaseBy = (currentCents - remainder) &amp;#x2F; coin;
      currentCents = currentCents % coin;
      const index = coinValues.length - 1 - coinValues.indexOf(coin);
      coins[index] += increaseBy;
    }
  }

  return coins;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(coinCombo(51));
&amp;#x2F;&amp;#x2F; [1, 0, 0, 2] ✅

console.log(coinCombo(26));
&amp;#x2F;&amp;#x2F; [1, 0, 0, 1] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-coin-combination&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;Array&lt;&#x2F;code&gt;, &lt;code&gt;for of&lt;&#x2F;code&gt;, &lt;code&gt;while&lt;&#x2F;code&gt;, &lt;code&gt;indexOf&lt;&#x2F;code&gt;, &lt;code&gt;%&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Array&quot;&gt;Array&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;while&quot;&gt;while&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;indexOf&quot;&gt;indexOf&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Remainder&quot;&gt;%&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: A Gift Well Spent</title>
        <published>2020-08-07T00:00:00+00:00</published>
        <updated>2020-08-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-07/" type="text/html"/>
        <id>https://miku86.com/2020-08-07/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;54554846126a002d5b000854&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;buy&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;giftCard&lt;&#x2F;code&gt; and &lt;code&gt;prices&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;You got a gift card for your local store. It has some credit you can use to buy things, but it may be used only for up to two items, and any credit you don&#x27;t use is lost. You want something for a friend and yourself. Therefore, you want to buy two items which add up the entire gift card value.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Given a gift card value, e.g. &lt;code&gt;5&lt;&#x2F;code&gt;, and a prices array, e.g. &lt;code&gt;[5, 2, 3, 4, 5]&lt;&#x2F;code&gt;
return the array indices that sum up to the gift card value out of the prices array, e.g. &lt;code&gt;[1, 2]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In this example, we can add up the prices &lt;code&gt;2&lt;&#x2F;code&gt; and &lt;code&gt;3&lt;&#x2F;code&gt; to our gift card value of &lt;code&gt;5&lt;&#x2F;code&gt; (=&amp;gt; &lt;code&gt;2 + 3 = 5&lt;&#x2F;code&gt;). Their indices are &lt;code&gt;1&lt;&#x2F;code&gt; and &lt;code&gt;2&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a number and an array of numbers.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an array of numbers.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Go to the first price element and look if there is another price that adds up to the gift card value&lt;&#x2F;li&gt;
&lt;li&gt;If not, go to the next price element and look if there is another price that adds up to the gift card value&lt;&#x2F;li&gt;
&lt;li&gt;Return the indices of the first pair of prices that add up to the gift card value&lt;&#x2F;li&gt;
&lt;li&gt;Return null, if there is no pair&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;5, [5, 2, 3, 4, 5]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Go to the first price element and look if there is another price that adds up to the gift card value: &lt;code&gt;5&lt;&#x2F;code&gt; =&amp;gt; no other price adds up to &lt;code&gt;5&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;If not, go to the next price element and look if there is another price that adds up to the gift card value: &lt;code&gt;2&lt;&#x2F;code&gt; =&amp;gt; we can find a &lt;code&gt;3&lt;&#x2F;code&gt; that adds up to &lt;code&gt;5&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the indices of the first pair of prices that add up to the gift card value: &lt;code&gt;[1, 2]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[1, 2]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function buy(giftCard, prices) {
  &amp;#x2F;&amp;#x2F; don&amp;#x27;t waste energy 🥵
  if (prices.length &amp;lt;= 1) return null;

  for (let i = 0; i &amp;lt; prices.length; i++) {
    for (let j = i + 1; j &amp;lt; prices.length; j++) {
      if (prices[i] + prices[j] === giftCard) {
        &amp;#x2F;&amp;#x2F; the indices of the first pair of prices that add up to the gift card value
        return [i, j];
      }
    }
  }

  &amp;#x2F;&amp;#x2F; no pair!
  return null;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(buy(5, [5, 2, 3, 4, 5]));
&amp;#x2F;&amp;#x2F; [1, 2] ✅

console.log(buy(3, [1, 1]));
&amp;#x2F;&amp;#x2F; null ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-a-gift-well-spent&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use a for loop.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for&quot;&gt;for&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Missing values</title>
        <published>2020-08-06T00:00:00+00:00</published>
        <updated>2020-08-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-06/" type="text/html"/>
        <id>https://miku86.com/2020-08-06/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, another &lt;code&gt;7 kyu&lt;&#x2F;code&gt; kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;58a66c208b88b2de660000c3&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;missingValues&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;myArray&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given an array of number, e.g. &lt;code&gt;[1, 1, 1, 2, 2, 3]&lt;&#x2F;code&gt;,&lt;&#x2F;p&gt;
&lt;p&gt;find:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;the number &lt;code&gt;x&lt;&#x2F;code&gt;, that appears once, e.g. &lt;code&gt;3&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;the number &lt;code&gt;y&lt;&#x2F;code&gt;, that appears twice, e.g. &lt;code&gt;2&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;and return the product &lt;code&gt;x&lt;&#x2F;code&gt; _ &lt;code&gt;x&lt;&#x2F;code&gt; _ &lt;code&gt;y&lt;&#x2F;code&gt;, e.g. &lt;code&gt;18&lt;&#x2F;code&gt; (=&amp;gt; &lt;code&gt;3 x 3 x 2&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: an array of numbers.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a number.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Find the number that appears once, &lt;code&gt;x&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find the number that appears twice, &lt;code&gt;y&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the product of &lt;code&gt;x * x * y&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[1, 1, 1, 2, 2, 3]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find the number that appears once, &lt;code&gt;x&lt;&#x2F;code&gt;: &lt;code&gt;3&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find the number that appears twice, &lt;code&gt;y&lt;&#x2F;code&gt;: &lt;code&gt;2&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the product of &lt;code&gt;x * x * y&lt;&#x2F;code&gt;: &lt;code&gt;18&lt;&#x2F;code&gt; (=&amp;gt; &lt;code&gt;3 x 3 x 2&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;18&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function missingValues(myArray) {
  &amp;#x2F;&amp;#x2F; count amount of each number
  const count = myArray.reduce(
    (acc, cur) =&amp;gt;
      acc.hasOwnProperty(cur)
        ? { ...acc, [cur]: acc[cur] + 1 }
        : { ...acc, [cur]: 1 },
    {}
  );

  &amp;#x2F;&amp;#x2F; helper function to find the object key (= our number) that appears [amount] times
  const appears = (amount) =&amp;gt;
    Object.entries(count)
      .filter(([key, value]) =&amp;gt; value === amount)
      .map((entry) =&amp;gt; entry[0]);

  return appears(1) * appears(1) * appears(2);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log([1, 1, 1, 2, 2, 3]);
&amp;#x2F;&amp;#x2F; 18 ✅

console.log([6, 5, 4, 100, 6, 5, 4, 100, 6, 5, 4, 200]);
&amp;#x2F;&amp;#x2F; 4000000 ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-missing-values&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;reduce&lt;&#x2F;code&gt;, &lt;code&gt;filter&lt;&#x2F;code&gt;, &lt;code&gt;map&lt;&#x2F;code&gt;, &lt;code&gt;hasOwnProperty&lt;&#x2F;code&gt;, &lt;code&gt;Object.entries&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Reduce&quot;&gt;reduce&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&#x2F;hasOwnProperty&quot;&gt;hasOwnProperty&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&#x2F;entries&quot;&gt;Object.entries&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Every possible sum of two digits</title>
        <published>2020-08-05T00:00:00+00:00</published>
        <updated>2020-08-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-05/" type="text/html"/>
        <id>https://miku86.com/2020-08-05/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Today, we&#x27;ll have a look at our first 7 kyu kata,
meaning we slightly increase the difficulty.&lt;&#x2F;p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5b4e474305f04bea11000148&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;everyPossibleSum&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;myNumber&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a number, e.g. &lt;code&gt;1234&lt;&#x2F;code&gt;,
return every possible sum of two digits, e.g. &lt;code&gt;[ 3, 4, 5, 5, 6, 7 ]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;For this example, we calculate:
&lt;code&gt;[ 1 + 2, 1 + 3, 1 + 4, 2 + 3, 2 + 4, 3 + 4 ]&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a number.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an array of numbers.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Get the single digits of the input number&lt;&#x2F;li&gt;
&lt;li&gt;Go to the first digit and find all sums with each next digit, starting from the second&lt;&#x2F;li&gt;
&lt;li&gt;Go to the second digit and find all sums with each next digit, starting from the third&lt;&#x2F;li&gt;
&lt;li&gt;Do this for every digit&lt;&#x2F;li&gt;
&lt;li&gt;Return the array with each sum in it&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;1234&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Go to the first digit and find all sums with each next digit, starting from the second: &lt;code&gt;1 + 2&lt;&#x2F;code&gt;, &lt;code&gt;1 + 3&lt;&#x2F;code&gt;, &lt;code&gt;1 + 4&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Go to the second digit and find all sums with each next digit, starting from the third: &lt;code&gt;2 + 3&lt;&#x2F;code&gt;, &lt;code&gt;2 + 4&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Do this for every digit: &lt;code&gt;3 + 4&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the array with each sum in it: &lt;code&gt;[ 3, 4, 5, 5, 6, 7 ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[ 3, 4, 5, 5, 6, 7 ]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function everyPossibleSum(myNumber) {
  &amp;#x2F;&amp;#x2F; split up number into its digits
  const split = String(myNumber) &amp;#x2F;&amp;#x2F; make it a string
    .split(&amp;quot;&amp;quot;) &amp;#x2F;&amp;#x2F; split it
    .map((digit) =&amp;gt; Number(digit)); &amp;#x2F;&amp;#x2F; convert each split char to a number

  const sums = [];

  &amp;#x2F;&amp;#x2F; first number: iterate from the first to the last number
  for (let first = 0; first &amp;lt; split.length; first++) {
    &amp;#x2F;&amp;#x2F; second number: iterate from the next number after the current first number to the last number
    for (let second = first + 1; second &amp;lt; split.length; second++) {
      Fiy;
      &amp;#x2F;&amp;#x2F; save the sum in the sums array
      sums.push(split[first] + split[second]);
    }
  }

  return sums;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(everyPossibleSum(1234));
&amp;#x2F;&amp;#x2F; [ 3, 4, 5, 5, 6, 7 ] ✅

console.log(everyPossibleSum(81596));
&amp;#x2F;&amp;#x2F; [ 9, 13, 17, 14, 6, 10, 7, 14, 11, 15 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-every-possible-sum-of-two-digits&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;String&lt;&#x2F;code&gt;, &lt;code&gt;split&lt;&#x2F;code&gt;, &lt;code&gt;map&lt;&#x2F;code&gt;, &lt;code&gt;for&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;String&quot;&gt;String&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for&quot;&gt;for&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Position in Alphabet</title>
        <published>2020-08-04T00:00:00+00:00</published>
        <updated>2020-08-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-04/" type="text/html"/>
        <id>https://miku86.com/2020-08-04/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5808e2006b65bff35500008f&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;positionInAlphabet&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;myChar&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a one-char string, e.g. &lt;code&gt;&amp;quot;a&amp;quot;&lt;&#x2F;code&gt;,
return the message &amp;quot;Position in Alphabet: [position]&amp;quot;, e.g. &lt;code&gt;&amp;quot;Position in Alphabet: 1&amp;quot;&lt;&#x2F;code&gt;.
If the input is uppercase, handle it like a lowercase character.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Convert the character into lowercase&lt;&#x2F;li&gt;
&lt;li&gt;Find the position of the char in the alphabet&lt;&#x2F;li&gt;
&lt;li&gt;Return the desired message with the position&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;a&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Convert the character into lowercase: &lt;code&gt;&amp;quot;a&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find the position of the char in the alphabet: &lt;code&gt;1&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return the desired message with the position: &lt;code&gt;&amp;quot;Position in Alphabet: 1&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;Position in Alphabet: 1&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-charcodeat&quot;&gt;Implementation (charCodeAt) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function positionInAlphabet(myChar) {
  const DIFFERENCE_CHARCODE_AND_LETTERS = 96;

  &amp;#x2F;&amp;#x2F; Convert the character into lowercase
  const myCharLowercase = myChar.toLowerCase();

  &amp;#x2F;&amp;#x2F; Find the position of the char in the alphabet
  const position =
    myCharLowercase.charCodeAt() - DIFFERENCE_CHARCODE_AND_LETTERS;

  &amp;#x2F;&amp;#x2F; Return the desired message with the position
  return `Position in Alphabet: ${position}`;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Where do we get the &lt;code&gt;96&lt;&#x2F;code&gt; from? When we go to the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.w3schools.com&#x2F;charsets&#x2F;ref_html_ascii.asp&quot;&gt;ASCII Table&lt;&#x2F;a&gt; and scroll down to the &lt;code&gt;a&lt;&#x2F;code&gt; in the &lt;code&gt;Char&lt;&#x2F;code&gt; column, we can see &lt;code&gt;97&lt;&#x2F;code&gt; in the &lt;code&gt;Number&lt;&#x2F;code&gt; column. So our &lt;code&gt;1&lt;&#x2F;code&gt;. char has the number &lt;code&gt;97&lt;&#x2F;code&gt;, our &lt;code&gt;2&lt;&#x2F;code&gt;. char has number &lt;code&gt;98&lt;&#x2F;code&gt; etc., meaning there is a difference of &lt;code&gt;96&lt;&#x2F;code&gt; between the char code (the &lt;code&gt;Number&lt;&#x2F;code&gt; column) and the actual char (the &lt;code&gt;Char&lt;&#x2F;code&gt; column).&lt;&#x2F;p&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(positionInAlphabet(&amp;quot;a&amp;quot;));
&amp;#x2F;&amp;#x2F; 1 ✅

console.log(positionInAlphabet(&amp;quot;Z&amp;quot;));
&amp;#x2F;&amp;#x2F; 26  ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-indexof&quot;&gt;Implementation (indexOf) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function positionInAlphabet(myChar) {
  const letters = [
    &amp;quot;a&amp;quot;,
    &amp;quot;b&amp;quot;,
    &amp;quot;c&amp;quot;,
    &amp;quot;d&amp;quot;,
    &amp;quot;e&amp;quot;,
    &amp;quot;f&amp;quot;,
    &amp;quot;g&amp;quot;,
    &amp;quot;h&amp;quot;,
    &amp;quot;i&amp;quot;,
    &amp;quot;j&amp;quot;,
    &amp;quot;k&amp;quot;,
    &amp;quot;l&amp;quot;,
    &amp;quot;m&amp;quot;,
    &amp;quot;n&amp;quot;,
    &amp;quot;o&amp;quot;,
    &amp;quot;p&amp;quot;,
    &amp;quot;q&amp;quot;,
    &amp;quot;r&amp;quot;,
    &amp;quot;s&amp;quot;,
    &amp;quot;t&amp;quot;,
    &amp;quot;u&amp;quot;,
    &amp;quot;v&amp;quot;,
    &amp;quot;w&amp;quot;,
    &amp;quot;x&amp;quot;,
    &amp;quot;y&amp;quot;,
    &amp;quot;z&amp;quot;,
  ];

  &amp;#x2F;&amp;#x2F; Convert the character into lowercase
  const myCharLowercase = myChar.toLowerCase();

  &amp;#x2F;&amp;#x2F; Find the position of the char in the alphabet
  const position = letters.indexOf(myCharLowercase) + 1;

  &amp;#x2F;&amp;#x2F; Return the desired message with the position
  return `Position in Alphabet: ${position}`;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(positionInAlphabet(&amp;quot;a&amp;quot;));
&amp;#x2F;&amp;#x2F; 1 ✅

console.log(positionInAlphabet(&amp;quot;Z&amp;quot;));
&amp;#x2F;&amp;#x2F; 26  ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-position-in-alphabet&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;toLowerCase&lt;&#x2F;code&gt;, &lt;code&gt;charCodeAt&lt;&#x2F;code&gt;, &lt;code&gt;indexOf&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;toLowerCase&quot;&gt;toLowerCase&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;charCodeAt&quot;&gt;charCodeAt&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;indexOf&quot;&gt;indexOf&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Freudian Translator</title>
        <published>2020-08-03T00:00:00+00:00</published>
        <updated>2020-08-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-08-03/" type="text/html"/>
        <id>https://miku86.com/2020-08-03/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5713bc89c82eff33c60009f7&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Today as small kata with a little bit of historical background about &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Sigmund_Freud&quot;&gt;Sigmund Freud&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;toFreud&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;myString&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a string, e.g. &lt;code&gt;&amp;quot;Sigmund Freud&amp;quot;&lt;&#x2F;code&gt;,
return the string with every word replaced by the word &lt;code&gt;&amp;quot;sex&amp;quot;&lt;&#x2F;code&gt;, e.g. &lt;code&gt;&amp;quot;sex sex&amp;quot;&lt;&#x2F;code&gt;.
An empty string or no argument should result in an empty string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Return an empty string if string is empty or no argument&lt;&#x2F;li&gt;
&lt;li&gt;Loop over every word of the string&lt;&#x2F;li&gt;
&lt;li&gt;Replace each word with &lt;code&gt;&amp;quot;sex&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return a string of all new words&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;Sigmund Freud&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return an empty string if string is empty or no argument: &lt;code&gt;false&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &amp;quot;Sigmund&amp;quot; =&amp;gt; replace it =&amp;gt; &lt;code&gt;&amp;quot;sex&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &amp;quot;Freud&amp;quot; =&amp;gt; replace it =&amp;gt; &lt;code&gt;&amp;quot;sex&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Return a string of all new words: &lt;code&gt;&amp;quot;sex sex&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;sex sex&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function toFreud(myString) {
  return !myString
    ? &amp;quot;&amp;quot; &amp;#x2F;&amp;#x2F; return an empty string if string is empty or no argument
    : myString
        .split(&amp;quot; &amp;quot;) &amp;#x2F;&amp;#x2F; split string into words
        .map((word) =&amp;gt; &amp;quot;sex&amp;quot;) &amp;#x2F;&amp;#x2F; replace each word with `&amp;quot;sex&amp;quot;`
        .join(&amp;quot; &amp;quot;); &amp;#x2F;&amp;#x2F; put replaced words together
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(toFreud(&amp;quot;Sigmund Freud&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;sex sex&amp;quot; ✅

console.log(toFreud(&amp;quot;&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;&amp;quot;  ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-regex&quot;&gt;Implementation (regex) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function toFreudRegex(myString) {
  return !myString ? &amp;quot;&amp;quot; : myString.replace(&amp;#x2F;\S+&amp;#x2F;g, &amp;quot;sex&amp;quot;); &amp;#x2F;&amp;#x2F; find all places that have &amp;quot;one or more non-white space&amp;quot;, replace them with &amp;quot;sex&amp;quot;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The regex &lt;code&gt;\S&lt;&#x2F;code&gt; character class &amp;quot;matches a single character other than white space&amp;quot;. You can read about it &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Guide&#x2F;Regular_Expressions&#x2F;Character_Classes&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The regex &lt;code&gt;+&lt;&#x2F;code&gt; quantifier &amp;quot;matches the preceding item 1 or more times&amp;quot;. You can read about it &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Guide&#x2F;Regular_Expressions&#x2F;Quantifiers&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(toFreud(&amp;quot;Sigmund Freud&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;sex sex&amp;quot; ✅

console.log(toFreud(&amp;quot;&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;&amp;quot;  ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-freudian-translator&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;split&lt;&#x2F;code&gt;, &lt;code&gt;map&lt;&#x2F;code&gt;, &lt;code&gt;join&lt;&#x2F;code&gt;, &lt;code&gt;replace&lt;&#x2F;code&gt; and some regex.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;join&quot;&gt;join&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;replace&quot;&gt;replace&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Guide&#x2F;Regular_Expressions&#x2F;Character_Classes&quot;&gt;regex character classes&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Guide&#x2F;Regular_Expressions&#x2F;Quantifiers&quot;&gt;regex quantifiers&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Is it a palindrome?</title>
        <published>2020-07-31T00:00:00+00:00</published>
        <updated>2020-07-31T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-31/" type="text/html"/>
        <id>https://miku86.com/2020-07-31/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57a1fd2ce298a731b20006a4&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;isPalindrome&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;myString&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a string, e.g. &lt;code&gt;&amp;quot;Abba&amp;quot;&lt;&#x2F;code&gt;,
return if this string is a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Palindrome&quot;&gt;palindrome&lt;&#x2F;a&gt; (case-insensitive), e.g. &lt;code&gt;true&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;A palindrome is a word [...] which reads the same backward as forward, such as &lt;code&gt;racecar&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a boolean.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Transform the input string to lowercase&lt;&#x2F;li&gt;
&lt;li&gt;Get the backward version of the lowercase string (= reverse it)&lt;&#x2F;li&gt;
&lt;li&gt;Check if the forward string is the same as the backward string&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;Abba&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Transform the input string to lowercase: &lt;code&gt;&amp;quot;abba&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Get the backward version of the lowercase string: &lt;code&gt;&amp;quot;abba&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Check if the forward string is the same as the backward string: &lt;code&gt;true&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;true&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function isPalindrome(myString) {
  &amp;#x2F;&amp;#x2F; transform the input string to lowercase
  const lowercaseInput = myString.toLowerCase();

  &amp;#x2F;&amp;#x2F; to have a similar wording
  const forward = lowercaseInput;

  &amp;#x2F;&amp;#x2F; get the backward version of the lowercase string
  const backward = lowercaseInput.split(&amp;quot;&amp;quot;).reverse().join(&amp;quot;&amp;quot;);

  &amp;#x2F;&amp;#x2F; check if the forward string is the same as the backward string
  return forward === backward;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(isPalindrome(&amp;quot;Abba&amp;quot;));
&amp;#x2F;&amp;#x2F; true ✅

console.log(isPalindrome(&amp;quot;hello&amp;quot;));
&amp;#x2F;&amp;#x2F; false ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-is-it-a-palindrome&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;toLowerCase&lt;&#x2F;code&gt;, &lt;code&gt;split&lt;&#x2F;code&gt;, &lt;code&gt;reverse&lt;&#x2F;code&gt;, &lt;code&gt;join&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;toLowerCase&quot;&gt;toLowerCase&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;reverse&quot;&gt;reverse&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;join&quot;&gt;join&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Classes: People</title>
        <published>2020-07-30T00:00:00+00:00</published>
        <updated>2020-07-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-30/" type="text/html"/>
        <id>https://miku86.com/2020-07-30/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;56f7f8215d7c12c0e7000b19&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s kata is a little bit different!&lt;&#x2F;p&gt;
&lt;p&gt;Define a class &lt;code&gt;Person&lt;&#x2F;code&gt;, that accepts four parameters in its constructor:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;firstName with the default value of &lt;code&gt;&amp;quot;John&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;lastName with the default value of &lt;code&gt;&amp;quot;Doe&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;age with the default value of &lt;code&gt;0&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;gender with the default value of &lt;code&gt;&amp;quot;Male&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;and stores them in &lt;code&gt;this&lt;&#x2F;code&gt; instance.&lt;&#x2F;p&gt;
&lt;p&gt;The class should also have two class methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method &lt;code&gt;sayFullName&lt;&#x2F;code&gt; that accepts no arguments and returns the full name, e.g. &amp;quot;John Doe&amp;quot;&lt;&#x2F;li&gt;
&lt;li&gt;a static method &lt;code&gt;greetExtraTerrestrials&lt;&#x2F;code&gt; that accepts one parameter &lt;code&gt;raceName&lt;&#x2F;code&gt; and returns &amp;quot;Welcome, [raceName]&amp;quot;, e.g. &amp;quot;Welcome, Martians&amp;quot;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create class skeleton&lt;&#x2F;li&gt;
&lt;li&gt;Create constructor&lt;&#x2F;li&gt;
&lt;li&gt;Add parameters and their default values to constructor&lt;&#x2F;li&gt;
&lt;li&gt;Store constructor parameters in instance&lt;&#x2F;li&gt;
&lt;li&gt;Add first method skeleton with parameters&lt;&#x2F;li&gt;
&lt;li&gt;Add return value of method&lt;&#x2F;li&gt;
&lt;li&gt;Add second method (static) skeleton with parameters&lt;&#x2F;li&gt;
&lt;li&gt;Add return value of method&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; class skeleton
class Person {
  &amp;#x2F;&amp;#x2F; constructor with parameters and their default values
  constructor(firstName = &amp;quot;John&amp;quot;, lastName = &amp;quot;Doe&amp;quot;, age = 0, gender = &amp;quot;Male&amp;quot;) {
    &amp;#x2F;&amp;#x2F; store constructor parameters in instance
    this.firstName = firstName;
    this.lastName = lastName;
    this.age = age;
    this.gender = gender;
  }

  &amp;#x2F;&amp;#x2F; first method skeleton with parameters
  sayFullName() {
    &amp;#x2F;&amp;#x2F; return value of method
    return `${this.firstName} ${this.lastName}`;
  }

  &amp;#x2F;&amp;#x2F; second method (static) skeleton with parameters
  static greetExtraTerrestrials(raceName) {
    &amp;#x2F;&amp;#x2F; return value of method
    return `Welcome, ${raceName}`;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(new Person(&amp;quot;Max&amp;quot;, &amp;quot;Mustermann&amp;quot;, 20, &amp;quot;Male&amp;quot;).firstName);
&amp;#x2F;&amp;#x2F; &amp;quot;Max&amp;quot; ✅

console.log(new Person(&amp;quot;Max&amp;quot;, &amp;quot;Mustermann&amp;quot;, 20, &amp;quot;Male&amp;quot;).lastName);
&amp;#x2F;&amp;#x2F; &amp;quot;Mustermann&amp;quot; ✅

console.log(new Person(&amp;quot;Max&amp;quot;, &amp;quot;Mustermann&amp;quot;, 20, &amp;quot;Male&amp;quot;).age);
&amp;#x2F;&amp;#x2F; 20 ✅

console.log(new Person(&amp;quot;Max&amp;quot;, &amp;quot;Mustermann&amp;quot;, 20, &amp;quot;Male&amp;quot;).gender);
&amp;#x2F;&amp;#x2F; &amp;quot;Male&amp;quot; ✅

console.log(new Person(&amp;quot;Max&amp;quot;, &amp;quot;Mustermann&amp;quot;, 20, &amp;quot;Male&amp;quot;).sayFullName());
&amp;#x2F;&amp;#x2F; &amp;quot;Max Mustermann&amp;quot; ✅

console.log(Person.greetExtraTerrestrials(&amp;quot;Martians&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;Welcome, Martians&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-classes-people&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use ES6 &lt;code&gt;class&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Classes&quot;&gt;class&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you use &lt;code&gt;class&lt;&#x2F;code&gt; in your JavaScript code?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Sort and Star</title>
        <published>2020-07-29T00:00:00+00:00</published>
        <updated>2020-07-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-29/" type="text/html"/>
        <id>https://miku86.com/2020-07-29/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57cfdf34902f6ba3d300001e&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;sortAndStar&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;stringArray&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given an array, e.g. &lt;code&gt;[&amp;quot;We&amp;quot;, &amp;quot;solve&amp;quot;, &amp;quot;Katas&amp;quot;]&lt;&#x2F;code&gt;,
sort it alphabetically (case-sensitive) and return the first string of the sorted array,
with all characters separated by &lt;code&gt;***&lt;&#x2F;code&gt; between each other, e.g. &lt;code&gt;&amp;quot;K***a***t***a***s&amp;quot;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: an array of strings.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Sort the array (case-sensitive)&lt;&#x2F;li&gt;
&lt;li&gt;Take the first array element&lt;&#x2F;li&gt;
&lt;li&gt;Put &lt;code&gt;***&lt;&#x2F;code&gt; between each char&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[&amp;quot;We&amp;quot;, &amp;quot;solve&amp;quot;, &amp;quot;Katas&amp;quot;]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Sort array: &lt;code&gt;[&amp;quot;Katas&amp;quot;, &amp;quot;We&amp;quot;, &amp;quot;solve&amp;quot;]&lt;&#x2F;code&gt; (case-sensitive)&lt;&#x2F;li&gt;
&lt;li&gt;Take first array element: &lt;code&gt;&amp;quot;Katas&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Put &lt;code&gt;***&lt;&#x2F;code&gt; between each char: &lt;code&gt;&amp;quot;K***a***t***a***s&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;K***a***t***a***s&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function sortAndStar(stringArray) {
  const sorted = stringArray.sort(); &amp;#x2F;&amp;#x2F; the default sort function works
  return sorted[0] &amp;#x2F;&amp;#x2F; take first element
    .split(&amp;quot;&amp;quot;) &amp;#x2F;&amp;#x2F; split string into chars
    .join(&amp;quot;***&amp;quot;); &amp;#x2F;&amp;#x2F; join chars with ***
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(sortAndStar([&amp;quot;We&amp;quot;, &amp;quot;solve&amp;quot;, &amp;quot;Katas&amp;quot;]));
&amp;#x2F;&amp;#x2F; &amp;quot;K***a***t***a***s&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-sort-and-star&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;sort&lt;&#x2F;code&gt;, &lt;code&gt;split&lt;&#x2F;code&gt; and &lt;code&gt;join&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;sort&quot;&gt;sort&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;join&quot;&gt;join&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Count lowercase letters</title>
        <published>2020-07-28T00:00:00+00:00</published>
        <updated>2020-07-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-28/" type="text/html"/>
        <id>https://miku86.com/2020-07-28/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;56a946cd7bd95ccab2000055&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;amountOfLowercaseLetters&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;inputString&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a string, e.g. &lt;code&gt;&amp;quot;aB1c&amp;quot;&lt;&#x2F;code&gt;,
return the number of lowercase letters in this string, e.g. &lt;code&gt;2&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a number.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Loop over every character&lt;&#x2F;li&gt;
&lt;li&gt;Check if it is a lowercase letter&lt;&#x2F;li&gt;
&lt;li&gt;If yes, then increase count of lowercase letters by 1&lt;&#x2F;li&gt;
&lt;li&gt;Return count of lowercase letters&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;aB1c&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: lowercase letter? &lt;code&gt;true&lt;&#x2F;code&gt; =&amp;gt; Increase count of lowercase letters by 1&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: lowercase letter? &lt;code&gt;false&lt;&#x2F;code&gt; =&amp;gt; Do nothing&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: lowercase letter? &lt;code&gt;false&lt;&#x2F;code&gt; =&amp;gt; Do nothing&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 4: lowercase letter? &lt;code&gt;true&lt;&#x2F;code&gt; =&amp;gt; Increase count of lowercase letters by 1&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;2&lt;&#x2F;code&gt; (count of lowercase letters) ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for&quot;&gt;Implementation (for) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function amountOfLowercaseLetters(inputString) {
  let count = 0;

  &amp;#x2F;&amp;#x2F; loop over every char
  for (const char of inputString) {
    &amp;#x2F;&amp;#x2F; check if it is lowercase
    if (char.match(&amp;#x2F;[a-z]&amp;#x2F;)) {
      &amp;#x2F;&amp;#x2F; if yes, increase count
      count += 1;
    }
  }

  return count;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(amountOfLowercaseLetters(&amp;quot;aB1c&amp;quot;));
&amp;#x2F;&amp;#x2F; 2 ✅

console.log(amountOfLowercaseLetters(&amp;quot;123&amp;quot;));
&amp;#x2F;&amp;#x2F; 0 ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function amountOfLowercaseLetters(inputString) {
  return inputString
    .split(&amp;quot;&amp;quot;) &amp;#x2F;&amp;#x2F; convert into array
    .filter((char) =&amp;gt; char.match(&amp;#x2F;[a-z]&amp;#x2F;)).length; &amp;#x2F;&amp;#x2F; filter out all lowercase chars &amp;#x2F;&amp;#x2F; take the length
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(amountOfLowercaseLetters(&amp;quot;aB1c&amp;quot;));
&amp;#x2F;&amp;#x2F; 2 ✅

console.log(amountOfLowercaseLetters(&amp;quot;123&amp;quot;));
&amp;#x2F;&amp;#x2F; 0 ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-global-regex&quot;&gt;Implementation (global regex) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function amountOfLowercaseLetters(inputString) {
  return (inputString.match(&amp;#x2F;[a-z]&amp;#x2F;g) || []).length;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We use the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;match#Return_value&quot;&gt;&lt;code&gt;g&lt;&#x2F;code&gt; flag to return all matches&lt;&#x2F;a&gt;. Because &lt;code&gt;null&lt;&#x2F;code&gt; would get returned if there wouldn&#x27;t be a match, we add an &lt;code&gt;[]&lt;&#x2F;code&gt; to use &lt;code&gt;length&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;result-2&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(amountOfLowercaseLetters(&amp;quot;aB1c&amp;quot;));
&amp;#x2F;&amp;#x2F; 2 ✅

console.log(amountOfLowercaseLetters(&amp;quot;123&amp;quot;));
&amp;#x2F;&amp;#x2F; 0 ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-count-lowercase-letters&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;for of&lt;&#x2F;code&gt;, &lt;code&gt;match&lt;&#x2F;code&gt;, &lt;code&gt;filter&lt;&#x2F;code&gt; and &lt;code&gt;length&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;match&quot;&gt;match&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;length&quot;&gt;length&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Repeat it</title>
        <published>2020-07-27T00:00:00+00:00</published>
        <updated>2020-07-27T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-27/" type="text/html"/>
        <id>https://miku86.com/2020-07-27/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s why I take interesting katas of all levels, customize them and explain how to solve them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercisegrey-exclama&quot;&gt;Understanding the Exercise❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!
If you don&#x27;t understand it, you can&#x27;t solve it!.&lt;&#x2F;p&gt;
&lt;p&gt;My personal method:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;557af9418895e44de7000053&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Write a function &lt;code&gt;repeatIt&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;inputString&lt;&#x2F;code&gt; and &lt;code&gt;repetitions&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a string, e.g. &lt;code&gt;&amp;quot;Hi&amp;quot;&lt;&#x2F;code&gt;,
and a number of repetitions, e.g. &lt;code&gt;2&lt;&#x2F;code&gt;,
return a string that repeats the input string n number of times, e.g. &lt;code&gt;&amp;quot;HiHi&amp;quot;&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;p&gt;If the input is not a string, return &amp;quot;Not a string&amp;quot;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string and a number.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Check if it is a string&lt;&#x2F;li&gt;
&lt;li&gt;If yes, then repeat it x times&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;Hi&amp;quot;, 2&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Check if it is a string: &lt;code&gt;true&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: add it to results =&amp;gt; &lt;code&gt;&amp;quot;Hi&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: add it to results =&amp;gt; &lt;code&gt;&amp;quot;HiHi&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;HiHi&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-native-method&quot;&gt;Implementation (native method) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function repeatIt(inputString, repetitions) {
  &amp;#x2F;&amp;#x2F; check if it is a string
  if (typeof inputString !== &amp;quot;string&amp;quot;) {
    return &amp;quot;Not a string&amp;quot;;
  }

  &amp;#x2F;&amp;#x2F; repeat it x times
  return inputString.repeat(repetitions);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(repeatIt(&amp;quot;Hi&amp;quot;, 2));
&amp;#x2F;&amp;#x2F; &amp;quot;HiHi&amp;quot; ✅

console.log(repeatIt(999, 1));
&amp;#x2F;&amp;#x2F; &amp;quot;Not a string&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function repeatIt(inputString, repetitions) {
  &amp;#x2F;&amp;#x2F; check if it is a string
  if (typeof inputString !== &amp;quot;string&amp;quot;) {
    return &amp;quot;Not a string&amp;quot;;
  }

  &amp;#x2F;&amp;#x2F; variable for result
  let result = &amp;quot;&amp;quot;;

  &amp;#x2F;&amp;#x2F; repeat it x times
  for (let i = 0; i &amp;lt; repetitions; i++) {
    &amp;#x2F;&amp;#x2F; add it to result
    result += inputString;
  }

  return result;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(repeatIt(&amp;quot;Hi&amp;quot;, 2));
&amp;#x2F;&amp;#x2F; &amp;quot;HiHi&amp;quot; ✅

console.log(repeatIt(999, 1));
&amp;#x2F;&amp;#x2F; &amp;quot;Not a string&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-repeat-it&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use &lt;code&gt;typeof&lt;&#x2F;code&gt;, &lt;code&gt;repeat&lt;&#x2F;code&gt; and &lt;code&gt;for&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;typeof&quot;&gt;typeof&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;repeat&quot;&gt;repeat&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for&quot;&gt;for loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Whose Move</title>
        <published>2020-07-24T00:00:00+00:00</published>
        <updated>2020-07-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-24/" type="text/html"/>
        <id>https://miku86.com/2020-07-24/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;59126992f9f87fd31600009b&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;whoseMove&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;lastPlayer&lt;&#x2F;code&gt; and &lt;code&gt;isWin&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a string of the last player, e.g. &lt;code&gt;&amp;quot;white&amp;quot;&lt;&#x2F;code&gt;,
and a string if s&#x2F;he won, e.g. &lt;code&gt;true&lt;&#x2F;code&gt;,
return a string whose turn it is, e.g. &lt;code&gt;&amp;quot;white&amp;quot;&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;if the last player has won, then it&#x27;s his&#x2F;her turn&lt;&#x2F;li&gt;
&lt;li&gt;if the last player has lost, then it&#x27;s the opponent&#x27;s turn&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: two strings.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Check if the last player has won&lt;&#x2F;li&gt;
&lt;li&gt;If yes (= has won), it&#x27;s the last player&#x27;s turn&lt;&#x2F;li&gt;
&lt;li&gt;If not (= has lost), it&#x27;s the opponent&#x27;s turn&lt;&#x2F;li&gt;
&lt;li&gt;Return the string whose turn it is&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;white&amp;quot;, true&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Check if the last player has won: &lt;code&gt;true&lt;&#x2F;code&gt; =&amp;gt; it&#x27;s the last player&#x27;s turn&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;white&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function whoseMove(lastPlayer, isWin) {
  &amp;#x2F;&amp;#x2F; check if player has won
  return isWin
    ? lastPlayer &amp;#x2F;&amp;#x2F; if yes, it&amp;#x27;s the last player&amp;#x27;s turn
    : lastPlayer === &amp;quot;white&amp;quot;
    ? &amp;quot;black&amp;quot; &amp;#x2F;&amp;#x2F; if not, and the last player was white, return black
    : &amp;quot;white&amp;quot;; &amp;#x2F;&amp;#x2F; if not, and the last player was black, return white
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(whoseMove(&amp;quot;white&amp;quot;, true));
&amp;#x2F;&amp;#x2F; &amp;quot;white&amp;quot; ✅

console.log(whoseMove(&amp;quot;black&amp;quot;, false));
&amp;#x2F;&amp;#x2F; &amp;quot;white&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-whose-move&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use the ternary operator.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Conditional_Operator&quot;&gt;ternary operator&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Well of Ideas - Easy</title>
        <published>2020-07-23T00:00:00+00:00</published>
        <updated>2020-07-23T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-23/" type="text/html"/>
        <id>https://miku86.com/2020-07-23/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57f222ce69e09c3630000212&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;getStatusOfWellOfIdeas&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;inputArray&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given an array of strings, e.g. &lt;code&gt;[&amp;quot;bad&amp;quot;, &amp;quot;good&amp;quot;, &amp;quot;bad&amp;quot;]&lt;&#x2F;code&gt;, return a message string of the status of the well of ideas:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;if the well of ideas includes 0 &amp;quot;good&amp;quot;: &lt;code&gt;&amp;quot;Fail!&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;if the well of ideas includes 1 or 2 &amp;quot;good&amp;quot;: &lt;code&gt;&amp;quot;Publish!&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;if the well of ideas includes more than 2 &amp;quot;good&amp;quot; =&amp;gt; &lt;code&gt;&amp;quot;I smell a series!&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: an array of strings.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Loop over every array element&lt;&#x2F;li&gt;
&lt;li&gt;Check if the current element is &lt;code&gt;good&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;If yes (= &lt;code&gt;good&lt;&#x2F;code&gt;), increase the counter of &lt;code&gt;good&lt;&#x2F;code&gt;s&lt;&#x2F;li&gt;
&lt;li&gt;Return the result string depending on the counter&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[&amp;quot;bad&amp;quot;, &amp;quot;good&amp;quot;, &amp;quot;bad&amp;quot;]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &lt;code&gt;&amp;quot;bad&amp;quot;&lt;&#x2F;code&gt; is &lt;code&gt;&amp;quot;good&amp;quot;&lt;&#x2F;code&gt;? =&amp;gt; No =&amp;gt; not increase counter =&amp;gt; 0&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &lt;code&gt;&amp;quot;good&amp;quot;&lt;&#x2F;code&gt; is &lt;code&gt;&amp;quot;good&amp;quot;&lt;&#x2F;code&gt;? =&amp;gt; Yes =&amp;gt; increase counter =&amp;gt; 1&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: &lt;code&gt;&amp;quot;bad&amp;quot;&lt;&#x2F;code&gt; is &lt;code&gt;&amp;quot;good&amp;quot;&lt;&#x2F;code&gt;? =&amp;gt; No =&amp;gt; not increase counter =&amp;gt; 1&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;Publish!&amp;quot;&lt;&#x2F;code&gt; (because 1 &lt;code&gt;good&lt;&#x2F;code&gt;) ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function getStatusOfWellOfIdeas(inputArray) {
  let goodCounter = 0;

  for (const idea of inputArray) {
    if (idea === &amp;quot;good&amp;quot;) {
      goodCounter += 1;
    }
  }

  return goodCounter === 0
    ? &amp;quot;Fail!&amp;quot;
    : goodCounter &amp;gt; 2
    ? &amp;quot;I smell a series!&amp;quot;
    : &amp;quot;Publish!&amp;quot;;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(getStatusOfWellOfIdeas([&amp;quot;bad&amp;quot;, &amp;quot;good&amp;quot;, &amp;quot;bad&amp;quot;]));
&amp;#x2F;&amp;#x2F; &amp;quot;Publish!&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function getStatusOfWellOfIdeas(inputArray) {
  const goodCounter = inputArray.filter((idea) =&amp;gt; idea === &amp;quot;good&amp;quot;).length;

  return goodCounter === 0
    ? &amp;quot;Fail!&amp;quot;
    : goodCounter &amp;gt; 2
    ? &amp;quot;I smell a series!&amp;quot;
    : &amp;quot;Publish!&amp;quot;;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(getStatusOfWellOfIdeas([&amp;quot;bad&amp;quot;, &amp;quot;good&amp;quot;, &amp;quot;bad&amp;quot;]));
&amp;#x2F;&amp;#x2F; &amp;quot;Publish!&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-well-of-ideas-easy&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use for of, ternary operator and filter.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Conditional_Operator&quot;&gt;ternary operator&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Polish Alphabet</title>
        <published>2020-07-22T00:00:00+00:00</published>
        <updated>2020-07-22T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-22/" type="text/html"/>
        <id>https://miku86.com/2020-07-22/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57ab2d6072292dbf7c000039&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;correctPolishLetters&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;inputString&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a string, e.g. &lt;code&gt;Wół&lt;&#x2F;code&gt;, return a string without the diacritics, e.g. &lt;code&gt;Wol&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;To keep it simple, we&#x27;ll just care about the lower case characters.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create a mapping of the characters with diacritics and without them&lt;&#x2F;li&gt;
&lt;li&gt;Loop over every character&lt;&#x2F;li&gt;
&lt;li&gt;Check if the current character has a diacritic&lt;&#x2F;li&gt;
&lt;li&gt;If yes (= has a diacritic), replace it with the character without diacritic&lt;&#x2F;li&gt;
&lt;li&gt;Return results&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;Wół&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &lt;code&gt;W&lt;&#x2F;code&gt; has diacritic? =&amp;gt; &lt;code&gt;No&lt;&#x2F;code&gt; =&amp;gt; not replace it =&amp;gt; &lt;code&gt;W&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &lt;code&gt;ó&lt;&#x2F;code&gt; has diacritic? =&amp;gt; &lt;code&gt;Yes&lt;&#x2F;code&gt; =&amp;gt; replace it =&amp;gt; &lt;code&gt;o&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: &lt;code&gt;ł&lt;&#x2F;code&gt; has diacritic? =&amp;gt; &lt;code&gt;Yes&lt;&#x2F;code&gt; =&amp;gt; replace it =&amp;gt; &lt;code&gt;l&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;Wol&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function correctPolishLetters(inputString) {
  &amp;#x2F;&amp;#x2F; mapping for characters
  const mapping = {
    ą: &amp;quot;a&amp;quot;,
    ć: &amp;quot;c&amp;quot;,
    ę: &amp;quot;e&amp;quot;,
    ł: &amp;quot;l&amp;quot;,
    ń: &amp;quot;n&amp;quot;,
    ó: &amp;quot;o&amp;quot;,
    ś: &amp;quot;s&amp;quot;,
    ź: &amp;quot;z&amp;quot;,
    ż: &amp;quot;z&amp;quot;,
  };

  &amp;#x2F;&amp;#x2F; variable to save result
  let withoutDiacritics = &amp;quot;&amp;quot;;

  &amp;#x2F;&amp;#x2F; loop over every number
  for (const char of inputString) {
    &amp;#x2F;&amp;#x2F; check if mapping has a key with the current character
    if (Object.keys(mapping).includes(char)) {
      withoutDiacritics += mapping[char];
      &amp;#x2F;&amp;#x2F; if yes, return its replacement
    } else {
      &amp;#x2F;&amp;#x2F; if not, return it unchanged
      withoutDiacritics += char;
    }
  }

  &amp;#x2F;&amp;#x2F; return result
  return withoutDiacritics;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(correctPolishLetters(&amp;quot;Wół&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;Wol&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function correctPolishLetters(inputString) {
  &amp;#x2F;&amp;#x2F; mapping for characters
  const mapping = {
    ą: &amp;quot;a&amp;quot;,
    ć: &amp;quot;c&amp;quot;,
    ę: &amp;quot;e&amp;quot;,
    ł: &amp;quot;l&amp;quot;,
    ń: &amp;quot;n&amp;quot;,
    ó: &amp;quot;o&amp;quot;,
    ś: &amp;quot;s&amp;quot;,
    ź: &amp;quot;z&amp;quot;,
    ż: &amp;quot;z&amp;quot;,
  };

  return (
    inputString
      &amp;#x2F;&amp;#x2F; split the string into an array
      .split(&amp;quot;&amp;quot;)
      .map(
        (char) =&amp;gt;
          &amp;#x2F;&amp;#x2F; check if mapping has a key with the current character
          Object.keys(mapping).includes(char)
            ? mapping[char] &amp;#x2F;&amp;#x2F; if yes, return its replacement
            : char &amp;#x2F;&amp;#x2F; if not, return it unchanged
      )
      &amp;#x2F;&amp;#x2F; join the array to a string
      .join(&amp;quot;&amp;quot;)
  );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(correctPolishLetters(&amp;quot;Wół&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;Wol&amp;quot; ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-polish-alphabet&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use a &lt;code&gt;for of&lt;&#x2F;code&gt; loop, &lt;code&gt;Object.keys()&lt;&#x2F;code&gt;, &lt;code&gt;includes&lt;&#x2F;code&gt; and &lt;code&gt;map&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&#x2F;keys&quot;&gt;Object.keys&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;includes&quot;&gt;includes&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;li&gt;What&#x27;s your simplest solution to add uppercase letters?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Remove duplicates</title>
        <published>2020-07-21T00:00:00+00:00</published>
        <updated>2020-07-21T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-21/" type="text/html"/>
        <id>https://miku86.com/2020-07-21/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57a5b0dfcf1fa526bb000118&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;removeDuplicates&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;inputArray&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a numbers array, e.g. &lt;code&gt;[1, 1, 2]&lt;&#x2F;code&gt;, return a numbers array without duplicates, e.g. &lt;code&gt;[1, 2]&lt;&#x2F;code&gt;. The order of the sequence has to stay the same.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a numbers array.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a numbers array.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Loop over every number&lt;&#x2F;li&gt;
&lt;li&gt;Check if current number has been seen before&lt;&#x2F;li&gt;
&lt;li&gt;If no (= not seen), save it into the results&lt;&#x2F;li&gt;
&lt;li&gt;Return results&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[1, 1, 2]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &lt;code&gt;1&lt;&#x2F;code&gt; been seen? =&amp;gt; &lt;code&gt;No&lt;&#x2F;code&gt; =&amp;gt; save it =&amp;gt; &lt;code&gt;[1]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &lt;code&gt;1&lt;&#x2F;code&gt; been seen? =&amp;gt; &lt;code&gt;Yes&lt;&#x2F;code&gt; =&amp;gt; do nothing =&amp;gt; &lt;code&gt;[1]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: &lt;code&gt;2&lt;&#x2F;code&gt; been seen? =&amp;gt; &lt;code&gt;No&lt;&#x2F;code&gt; =&amp;gt; save it =&amp;gt; &lt;code&gt;[1, 2]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[1, 2]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function removeDuplicates(inputNumbers) {
  &amp;#x2F;&amp;#x2F; variable to save result
  const withoutDuplicates = [];

  &amp;#x2F;&amp;#x2F; loop over every number
  for (const number of inputNumbers) {
    &amp;#x2F;&amp;#x2F; check if current number has been seen before
    &amp;#x2F;&amp;#x2F; if no (= not seen), save it into the results
    if (!withoutDuplicates.includes(number)) {
      withoutDuplicates.push(number);
    }
  }

  &amp;#x2F;&amp;#x2F; return result
  return withoutDuplicates;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(removeDuplicates([1, 1, 2]));
&amp;#x2F;&amp;#x2F; [ 1, 2 ] ✅

console.log(removeDuplicates([3, 3, 2, 2, 1]));
&amp;#x2F;&amp;#x2F; [ 3, 2, 1 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function removeDuplicates(inputNumbers) {
  return inputNumbers.reduce(
    (accumulated, current) =&amp;gt; {
      &amp;#x2F;&amp;#x2F; check if current number has been seen before
      return accumulated.includes(current)
        ? accumulated &amp;#x2F;&amp;#x2F; if yes (= already seen), return the old values without changes
        : accumulated.concat(current); &amp;#x2F;&amp;#x2F; if no (= not seen), return the old values plus the current one
    },
    [] &amp;#x2F;&amp;#x2F; we start with an empty array (like &amp;quot;withoutDuplicates&amp;quot; in the alternative solution)
  );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I&#x27;m using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;concat&quot;&gt;&lt;code&gt;concat&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; to connect the old values with the current one. You can also use the spread operator like we did &lt;a href=&quot;&#x2F;js-katas-count-sheep&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(removeDuplicates([1, 1, 2]));
&amp;#x2F;&amp;#x2F; [ 1, 2 ] ✅

console.log(removeDuplicates([3, 3, 2, 2, 1]));
&amp;#x2F;&amp;#x2F; [ 3, 2, 1 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-set&quot;&gt;Implementation (Set) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function removeDuplicates(inputNumbers) {
  &amp;#x2F;&amp;#x2F; we go from array (inputNumbers) to set (new Set()) to array (...)
  return [...new Set(inputNumbers)];
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In JavaScript, in the &lt;code&gt;Set&lt;&#x2F;code&gt; data structure a value may only occur once and the order is preserved, so this solves our problem too. If you don&#x27;t use JavaScript, pay attention to the fact, that not every programming language keeps the original order in a &lt;code&gt;Set&lt;&#x2F;code&gt;. (Thanks to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;pentacular&#x2F;comment&#x2F;12ajl&quot;&gt;@pentacular&lt;&#x2F;a&gt;)&lt;&#x2F;p&gt;
&lt;p&gt;We use a temporary change in the data structure (a &lt;code&gt;Set&lt;&#x2F;code&gt;) to remove our duplicates. Then we convert the &lt;code&gt;Set&lt;&#x2F;code&gt; back to an array.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;result-2&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(removeDuplicates([1, 1, 2]));
&amp;#x2F;&amp;#x2F; [ 1, 2 ] ✅

console.log(removeDuplicates([3, 3, 2, 2, 1]));
&amp;#x2F;&amp;#x2F; [ 3, 2, 1 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-remove-duplicates&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use a &lt;code&gt;for of&lt;&#x2F;code&gt; loop, a lot of functional stuff and &lt;code&gt;Set&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;includes&quot;&gt;includes&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Reduce&quot;&gt;reduce&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;concat&quot;&gt;concat&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Spread_syntax&quot;&gt;[...]&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Set&quot;&gt;Set&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;li&gt;Have you ever used a &lt;code&gt;Set&lt;&#x2F;code&gt;?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Divisible By</title>
        <published>2020-07-18T00:00:00+00:00</published>
        <updated>2020-07-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-18/" type="text/html"/>
        <id>https://miku86.com/2020-07-18/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;55edaba99da3a9c84000003b&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;divisibleBy&lt;&#x2F;code&gt;, that accepts two parameters: &lt;code&gt;numbers&lt;&#x2F;code&gt; and &lt;code&gt;divisor&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a numbers array, e.g. &lt;code&gt;[1, 2, 3, 4, 5, 6]&lt;&#x2F;code&gt;,
and a divisor, e.g. &lt;code&gt;2&lt;&#x2F;code&gt;,
return an array with all numbers divisible by the given divisor, e.g. &lt;code&gt;[2, 4, 6]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a numbers array and a number.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a numbers array.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Loop over every number&lt;&#x2F;li&gt;
&lt;li&gt;Check if current number is divisible by divisor&lt;&#x2F;li&gt;
&lt;li&gt;If yes, save it into results variable&lt;&#x2F;li&gt;
&lt;li&gt;Return results&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;([1, 2, 3, 4, 5, 6], 2)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: Is &lt;code&gt;1&lt;&#x2F;code&gt; divisible by &lt;code&gt;2&lt;&#x2F;code&gt;? &lt;code&gt;No&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: Is &lt;code&gt;2&lt;&#x2F;code&gt; divisible by &lt;code&gt;2&lt;&#x2F;code&gt;? &lt;code&gt;Yes&lt;&#x2F;code&gt; =&amp;gt; Save it into results variable =&amp;gt; &lt;code&gt;[2]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: Is &lt;code&gt;3&lt;&#x2F;code&gt; divisible by &lt;code&gt;2&lt;&#x2F;code&gt;? &lt;code&gt;No&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 4: Is &lt;code&gt;4&lt;&#x2F;code&gt; divisible by &lt;code&gt;2&lt;&#x2F;code&gt;? &lt;code&gt;Yes&lt;&#x2F;code&gt; =&amp;gt; Save it into results variable =&amp;gt; &lt;code&gt;[2, 4]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 5: Is &lt;code&gt;5&lt;&#x2F;code&gt; divisible by &lt;code&gt;2&lt;&#x2F;code&gt;? &lt;code&gt;No&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 6: Is &lt;code&gt;6&lt;&#x2F;code&gt; divisible by &lt;code&gt;2&lt;&#x2F;code&gt;? &lt;code&gt;Yes&lt;&#x2F;code&gt; =&amp;gt; Save it into results variable =&amp;gt; &lt;code&gt;[2, 4, 6]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;[2, 4, 6]&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function divisibleBy(numbers, divisor) {
  &amp;#x2F;&amp;#x2F; create variable for results
  const result = [];

  &amp;#x2F;&amp;#x2F; loop over numbers
  for (const n of numbers) {
    &amp;#x2F;&amp;#x2F; check if current number is divisible by divisor
    if (n % divisor === 0) {
      &amp;#x2F;&amp;#x2F; if yes, save it into results variable
      result.push(n);
    }
  }

  &amp;#x2F;&amp;#x2F; return results
  return result;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(divisibleBy([1, 2, 3, 4, 5, 6], 2));
&amp;#x2F;&amp;#x2F; [ 2, 4, 6 ] ✅

console.log(divisibleBy([1, 2, 3, 4, 5, 6], 3));
&amp;#x2F;&amp;#x2F; [ 3, 6 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function divisibleBy(numbers, divisor) {
  &amp;#x2F;&amp;#x2F; return each number that is divisible by the divisor
  return numbers.filter((n) =&amp;gt; n % divisor === 0);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(divisibleBy([1, 2, 3, 4, 5, 6], 2));
&amp;#x2F;&amp;#x2F; [ 2, 4, 6 ] ✅

console.log(divisibleBy([1, 2, 3, 4, 5, 6], 3));
&amp;#x2F;&amp;#x2F; [ 3, 6 ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-divisible-by&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use the &lt;code&gt;for of&lt;&#x2F;code&gt;-loop and the &lt;code&gt;filter&lt;&#x2F;code&gt; method.&lt;&#x2F;p&gt;
&lt;p&gt;I hope that you can use your new learnings to solve problems more easily!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Card Suit</title>
        <published>2020-07-17T00:00:00+00:00</published>
        <updated>2020-07-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-17/" type="text/html"/>
        <id>https://miku86.com/2020-07-17/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5a360620f28b82a711000047&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;defineSuit&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;card&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a card string, e.g. &lt;code&gt;&amp;quot;3♣&amp;quot;&lt;&#x2F;code&gt;, return a string with the term for the card&#x27;s suit, e.g. &lt;code&gt;&amp;quot;clubs&amp;quot;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string (a card).&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string (the card&#x27;s suit)&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;create a mapping of the card&#x27;s suit sign and its suit term&lt;&#x2F;li&gt;
&lt;li&gt;find the sign of the suit in the string&lt;&#x2F;li&gt;
&lt;li&gt;find term in the mapping&lt;&#x2F;li&gt;
&lt;li&gt;return the term of the suit&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;3♣&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Create mapping: &lt;code&gt;{ &amp;quot;♣&amp;quot;: &amp;quot;clubs&amp;quot;, &amp;quot;♠&amp;quot;: &amp;quot;spades&amp;quot;, &amp;quot;♦&amp;quot;: &amp;quot;diamonds&amp;quot;, &amp;quot;♥&amp;quot;: &amp;quot;hearts&amp;quot; }&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find suit sign: &lt;code&gt;&amp;quot;♣&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Find term: &lt;code&gt;&amp;quot;clubs&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;clubs&amp;quot;&lt;&#x2F;code&gt; ✅&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function defineSuit(card) {
  &amp;#x2F;&amp;#x2F; create mapping
  const mappingSignToTerm = {
    &amp;quot;♣&amp;quot;: &amp;quot;clubs&amp;quot;,
    &amp;quot;♠&amp;quot;: &amp;quot;spades&amp;quot;,
    &amp;quot;♦&amp;quot;: &amp;quot;diamonds&amp;quot;,
    &amp;quot;♥&amp;quot;: &amp;quot;hearts&amp;quot;,
  };

  &amp;#x2F;&amp;#x2F; find suit sign (seems to be the last character)
  const suitSign = card.slice(-1);

  &amp;#x2F;&amp;#x2F; find term in the mapping
  const suitTerm = mappingSignToTerm[suitSign];

  &amp;#x2F;&amp;#x2F; return term
  return suitTerm;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(defineSuit(&amp;quot;3♣&amp;quot;));
&amp;#x2F;&amp;#x2F; clubs ✅

console.log(defineSuit(&amp;quot;Q♠&amp;quot;));
&amp;#x2F;&amp;#x2F; spades ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-card-suit&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;I hope, that this was a fairly easy one!&lt;&#x2F;p&gt;
&lt;p&gt;We learned how to use an object for our mapping.&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&quot;&gt;Object&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Count sheep</title>
        <published>2020-07-16T00:00:00+00:00</published>
        <updated>2020-07-16T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-16/" type="text/html"/>
        <id>https://miku86.com/2020-07-16/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5b077ebdaf15be5c7f000077&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;countSheep&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;amountOfSheep&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Given a non-negative number, e.g. &lt;code&gt;3&lt;&#x2F;code&gt;, return a string with &lt;code&gt;&amp;quot;1 sheep...2 sheep...3 sheep...&amp;quot;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a number (of sheep).&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;create a variable to save the result&lt;&#x2F;li&gt;
&lt;li&gt;create message based on the current number&lt;&#x2F;li&gt;
&lt;li&gt;add it to the result variable&lt;&#x2F;li&gt;
&lt;li&gt;repeat this until reaching the last number (= amountOfSheep)&lt;&#x2F;li&gt;
&lt;li&gt;return the result&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;3&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &lt;code&gt;[&amp;quot;1 sheep...&amp;quot;]&lt;&#x2F;code&gt; &#x2F;&#x2F; create message based on the current number, add it to the result&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &lt;code&gt;[&amp;quot;1 sheep...&amp;quot;, &amp;quot;2 sheep...&amp;quot;]&lt;&#x2F;code&gt; &#x2F;&#x2F; create message based on the current number&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: &lt;code&gt;[&amp;quot;1 sheep...&amp;quot;, &amp;quot;2 sheep...&amp;quot;, &amp;quot;3 sheep...&amp;quot;]&lt;&#x2F;code&gt; &#x2F;&#x2F; create message based on the current number&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;1 sheep...2 sheep...3 sheep...&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; create the output string&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function countSheep(amountOfSheep) {
  &amp;#x2F;&amp;#x2F; create a variable to save the result
  let result = &amp;quot;&amp;quot;;

  for (let i = 1; i &amp;lt;= amountOfSheep; i++) {
    &amp;#x2F;&amp;#x2F; create message based on the current number, add it to the result
    result += `${i} sheep...`;
  }

  return result;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(countSheep(3));
&amp;#x2F;&amp;#x2F; 1 sheep...2 sheep...3 sheep...

console.log(countSheep(1));
&amp;#x2F;&amp;#x2F; 1 sheep...
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function countSheep(amountOfSheep) {
  return (
    [...Array(amountOfSheep)]
      &amp;#x2F;&amp;#x2F; create message based on the current number
      .map((_, i) =&amp;gt; `${i + 1} sheep...`)
      &amp;#x2F;&amp;#x2F; &amp;quot;add&amp;quot; it to the result
      .join(&amp;quot;&amp;quot;)
  );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(countSheep(3));
&amp;#x2F;&amp;#x2F; 1 sheep...2 sheep...3 sheep...

console.log(countSheep(1));
&amp;#x2F;&amp;#x2F; 1 sheep...
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-count-sheep&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve another interesting kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for&quot;&gt;for loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Array&quot;&gt;Array&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Spread_syntax&quot;&gt;[...]&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;join&quot;&gt;join&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How often do you do katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Abbreviate a two word name</title>
        <published>2020-07-15T00:00:00+00:00</published>
        <updated>2020-07-15T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-15/" type="text/html"/>
        <id>https://miku86.com/2020-07-15/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57eadb7ecd143f4c9c0000a3&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;abbreviateName&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;name&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;name&lt;&#x2F;code&gt; is a string that includes two words, with one space in between them, e.g. &amp;quot;John Doe&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;The output should be the two first characters, both capitalized with a dot separating them, e.g. &amp;quot;J.D&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;&amp;quot;John Doe&amp;quot;&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;&amp;quot;J.D&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;&amp;quot;john doe&amp;quot;&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;&amp;quot;J.D&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;split the name into two words&lt;&#x2F;li&gt;
&lt;li&gt;take the first character of the word&lt;&#x2F;li&gt;
&lt;li&gt;capitalize this character&lt;&#x2F;li&gt;
&lt;li&gt;do this for both words&lt;&#x2F;li&gt;
&lt;li&gt;join both characters with a dot&lt;&#x2F;li&gt;
&lt;li&gt;return the joined characters&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;john doe&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Split them: &lt;code&gt;[&amp;quot;john&amp;quot;, &amp;quot;doe&amp;quot;]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Take 1st char: &lt;code&gt;&amp;quot;j&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; 1st word&lt;&#x2F;li&gt;
&lt;li&gt;Capitalize it: &lt;code&gt;&amp;quot;J&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; 1st word&lt;&#x2F;li&gt;
&lt;li&gt;Take 1st char: &lt;code&gt;&amp;quot;d&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; 2nd word&lt;&#x2F;li&gt;
&lt;li&gt;Capitalize it: &lt;code&gt;&amp;quot;D&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; 2nd word&lt;&#x2F;li&gt;
&lt;li&gt;Join them with a dot: &lt;code&gt;&amp;quot;J.D&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;J.D&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function abbreviateName(name) {
  return (
    name
      &amp;#x2F;&amp;#x2F; split the name into two words
      .split(&amp;quot; &amp;quot;)

      &amp;#x2F;&amp;#x2F; take first char of both parts and capitalize them
      .map((part) =&amp;gt; part[0].toUpperCase())

      &amp;#x2F;&amp;#x2F; join both characters with a dot
      .join(&amp;quot;.&amp;quot;)
  );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(abbreviateName(&amp;quot;John Doe&amp;quot;));
&amp;#x2F;&amp;#x2F; J.D

console.log(abbreviateName(&amp;quot;john doe&amp;quot;));
&amp;#x2F;&amp;#x2F; J.D
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-abbreviate-two-word-name&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve the next kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;join&quot;&gt;join&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you like to solve katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Calculate total amount of points</title>
        <published>2020-07-14T00:00:00+00:00</published>
        <updated>2020-07-14T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-14/" type="text/html"/>
        <id>https://miku86.com/2020-07-14/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5bb904724c47249b10000131&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;calculateAmountOfPoints&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;games&lt;&#x2F;code&gt;, a valid array of strings, e.g. &lt;code&gt;[&amp;quot;3:1&amp;quot;, &amp;quot;2:2&amp;quot;]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Points:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;x &amp;gt; y: 3 points&lt;&#x2F;li&gt;
&lt;li&gt;x = y: 1 point&lt;&#x2F;li&gt;
&lt;li&gt;x &amp;lt; y: 0 point&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The function should return a number. The number is the sum of the point(s) of every single game.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: an array of strings.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a number.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;loop over every element of the games array&lt;&#x2F;li&gt;
&lt;li&gt;calculate the specific score of this element&lt;&#x2F;li&gt;
&lt;li&gt;return the sum of every single element (a number)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[&amp;quot;3:1&amp;quot;, &amp;quot;2:2&amp;quot;]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &lt;code&gt;&amp;quot;3:1&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; x &amp;gt; y =&amp;gt; 3 points&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &lt;code&gt;&amp;quot;2:2&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; x = y =&amp;gt; 1 point&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;4&lt;&#x2F;code&gt; &#x2F;&#x2F; return the sum (3 + 1) as a number&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-of-loop&quot;&gt;Implementation (for of-loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function calculateAmountOfPoints(games) {
  &amp;#x2F;&amp;#x2F; counter for total points
  let totalPoints = 0;

  for (const game of games) {
    &amp;#x2F;&amp;#x2F; split the game score for both teams and assign it to two variables
    const [scoreA, scoreB] = game.split(&amp;quot;:&amp;quot;);

    &amp;#x2F;&amp;#x2F; calculate the points for this game with a ternary operator
    const points = scoreA &amp;gt; scoreB ? 3 : scoreA === scoreB ? 1 : 0;

    &amp;#x2F;&amp;#x2F; add the points for this specific game to the total points
    totalPoints += points;
  }

  return totalPoints;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(calculateAmountOfPoints([&amp;quot;3:1&amp;quot;, &amp;quot;2:2&amp;quot;]));
&amp;#x2F;&amp;#x2F; 4

console.log(calculateAmountOfPoints([&amp;quot;1:0&amp;quot;, &amp;quot;2:0&amp;quot;, &amp;quot;3:0&amp;quot;, &amp;quot;4:0&amp;quot;, &amp;quot;2:1&amp;quot;]));
&amp;#x2F;&amp;#x2F; 15
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function calculateAmountOfPoints(games) {
  return (
    games
      &amp;#x2F;&amp;#x2F; split the game score into two separate values
      .map((game) =&amp;gt; game.split(&amp;quot;:&amp;quot;))

      &amp;#x2F;&amp;#x2F; calculate the points for this game with a ternary operator
      .map((score) =&amp;gt; (score[0] &amp;gt; score[1] ? 3 : score[0] === score[1] ? 1 : 0))

      &amp;#x2F;&amp;#x2F; calculate the sum of all games
      .reduce((acc, cur) =&amp;gt; acc + cur, 0)
  );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(calculateAmountOfPoints([&amp;quot;3:1&amp;quot;, &amp;quot;2:2&amp;quot;]));
&amp;#x2F;&amp;#x2F; 4

console.log(calculateAmountOfPoints([&amp;quot;1:0&amp;quot;, &amp;quot;2:0&amp;quot;, &amp;quot;3:0&amp;quot;, &amp;quot;4:0&amp;quot;, &amp;quot;2:1&amp;quot;]));
&amp;#x2F;&amp;#x2F; 15
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-total-amount-points&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve the next kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of-loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Operators&#x2F;Conditional_Operator&quot;&gt;ternary&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Reduce&quot;&gt;reduce&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you like to solve katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Correct the mistakes of the character recognition software</title>
        <published>2020-07-13T00:00:00+00:00</published>
        <updated>2020-07-13T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-13/" type="text/html"/>
        <id>https://miku86.com/2020-07-13/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;577bd026df78c19bca0002c0&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Character recognition software is widely used to digitize printed texts. When documents are digitized character recognition softwares often make mistakes. Your task is to correct the errors in the digitized text. You only have to handle the following mistakes:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;S&lt;&#x2F;code&gt; is misinterpreted as &lt;code&gt;5&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;O&lt;&#x2F;code&gt; is misinterpreted as &lt;code&gt;0&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;I&lt;&#x2F;code&gt; is misinterpreted as &lt;code&gt;1&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Write a function &lt;code&gt;correctMistakes&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;inputString&lt;&#x2F;code&gt;, a valid string.&lt;&#x2F;p&gt;
&lt;p&gt;The function should return a string. The string contains the &lt;code&gt;inputString&lt;&#x2F;code&gt; with the corrections.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string with the corrections.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;loop over every character&lt;&#x2F;li&gt;
&lt;li&gt;if the character is misinterpreted (see above), correct it&lt;&#x2F;li&gt;
&lt;li&gt;return the result (the corrected string)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;0h!&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &lt;code&gt;&amp;quot;0h!&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; next character is &lt;code&gt;0&lt;&#x2F;code&gt; =&amp;gt; it is in the list of corrections =&amp;gt; correct it (&lt;code&gt;0&lt;&#x2F;code&gt; becomes &lt;code&gt;O&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &lt;code&gt;&amp;quot;Oh!&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; next character is &lt;code&gt;h&lt;&#x2F;code&gt; =&amp;gt; it is NOT in the list of corrections =&amp;gt; return it unchanged&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: &lt;code&gt;&amp;quot;Oh!&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; next character is &lt;code&gt;!&lt;&#x2F;code&gt; =&amp;gt; it is NOT in the list of corrections =&amp;gt; return it unchanged&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;Oh!&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; return the string&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function correctMistakes(inputString) {
  &amp;#x2F;&amp;#x2F; organize the corrections in a human-readable object&amp;#x2F;map
  const corrections = {
    5: &amp;quot;S&amp;quot;,
    0: &amp;quot;O&amp;quot;,
    1: &amp;quot;I&amp;quot;,
  };

  return (
    inputString
      &amp;#x2F;&amp;#x2F; split the string into an array of characters
      .split(&amp;quot;&amp;quot;)
      &amp;#x2F;&amp;#x2F; check if the current character is in the corrections object
      &amp;#x2F;&amp;#x2F; if it is, correct it, else return it unchanged
      .map((char) =&amp;gt;
        corrections.hasOwnProperty(char) ? corrections[char] : char
      )
      &amp;#x2F;&amp;#x2F; join the array of characters to a string
      .join(&amp;quot;&amp;quot;)
  );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(correctMistakes(&amp;quot;0h!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;Oh!&amp;quot;

console.log(correctMistakes(&amp;quot;1 l0ve m1ss1ss1pp1🧶!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;I lOve mIssIssIppI🧶!&amp;quot;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-regex&quot;&gt;Implementation (regex) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function correctMistakes(inputString) {
  &amp;#x2F;&amp;#x2F; organize the corrections in a human-readable object&amp;#x2F;map
  const corrections = {
    5: &amp;quot;S&amp;quot;,
    0: &amp;quot;O&amp;quot;,
    1: &amp;quot;I&amp;quot;,
  };

  &amp;#x2F;&amp;#x2F; use a regex (&amp;#x2F;&amp;#x2F;)
  &amp;#x2F;&amp;#x2F; search for 5 or 0 or 1 ([501])
  &amp;#x2F;&amp;#x2F; do this for the whole input (g)
  &amp;#x2F;&amp;#x2F; if it finds a mistake, run the function that takes the mistake and replaces it with the correct char from the corrections object
  return inputString.replace(&amp;#x2F;[501]&amp;#x2F;g, (char) =&amp;gt; corrections[char]);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(correctMistakes(&amp;quot;0h!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;Oh!&amp;quot;

console.log(correctMistakes(&amp;quot;1 l0ve m1ss1ss1pp1🧶!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;I lOve mIssIssIppI🧶!&amp;quot;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-correct-mistakes-recognition-software&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve the next kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;split&quot;&gt;split&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;map&quot;&gt;map&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Object&#x2F;hasOwnProperty&quot;&gt;hasOwnProperty&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;join&quot;&gt;join&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;replace&quot;&gt;replace&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;replace#Specifying_a_function_as_a_parameter&quot;&gt;replace: function as param&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;RegExp&quot;&gt;regex&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;regex101.com&#x2F;&quot;&gt;regex playground&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you like to solve katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;li&gt;Do you regularly use regex?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Remove all exclamation marks from the end</title>
        <published>2020-07-12T00:00:00+00:00</published>
        <updated>2020-07-12T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-12/" type="text/html"/>
        <id>https://miku86.com/2020-07-12/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;57faece99610ced690000165&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;removeExclamationMarksFromEnd&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;inputString&lt;&#x2F;code&gt;, a valid string.&lt;&#x2F;p&gt;
&lt;p&gt;The function should return a string. The string contains the &lt;code&gt;inputString&lt;&#x2F;code&gt;, but without an exclamation mark at the end.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: a string that has no exclamation mark at the end.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;have a look at the last character&lt;&#x2F;li&gt;
&lt;li&gt;if it is a &lt;code&gt;!&lt;&#x2F;code&gt;, remove it&lt;&#x2F;li&gt;
&lt;li&gt;repeat from step #1 while last character is a &lt;code&gt;!&lt;&#x2F;code&gt; (while loop?)&lt;&#x2F;li&gt;
&lt;li&gt;return the result (a string)&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;bee!!&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 1: &lt;code&gt;&amp;quot;bee!!&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; last character is &lt;code&gt;!&lt;&#x2F;code&gt; =&amp;gt; remove it and repeat&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 2: &lt;code&gt;&amp;quot;bee!&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; last character is &lt;code&gt;!&lt;&#x2F;code&gt; =&amp;gt; remove it and repeat&lt;&#x2F;li&gt;
&lt;li&gt;Iteration 3: &lt;code&gt;&amp;quot;bee&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; last character is NOT &lt;code&gt;!&lt;&#x2F;code&gt; =&amp;gt; break out of the loop&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;&amp;quot;bee&amp;quot;&lt;&#x2F;code&gt; &#x2F;&#x2F; return the string&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-while-loop&quot;&gt;Implementation (while loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function removeExclamationMarksFromEnd(inputString) {
  let result = inputString;

  &amp;#x2F;&amp;#x2F; run this loop while the last character is a `!`
  while (result[result.length - 1] === &amp;quot;!&amp;quot;) {
    &amp;#x2F;&amp;#x2F; remove the last character (= `!`)
    result = result.slice(0, -1);
  }

  return result;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(removeExclamationMarksFromEnd(&amp;quot;bee!!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;bee&amp;quot;

console.log(removeExclamationMarksFromEnd(&amp;quot;Hey! Bee🧶!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;Hey! Bee🧶!&amp;quot;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-regex&quot;&gt;Implementation (regex) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function removeExclamationMarksFromEnd(inputString) {
  &amp;#x2F;&amp;#x2F; use a regex (&amp;#x2F;&amp;#x2F;)
  &amp;#x2F;&amp;#x2F; replace one or more exclamation marks (!+) from the end ($) with an empty string (&amp;quot;&amp;quot;)
  return inputString.replace(&amp;#x2F;!+$&amp;#x2F;, &amp;quot;&amp;quot;);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(removeExclamationMarksFromEnd(&amp;quot;bee!!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;bee&amp;quot;

console.log(removeExclamationMarksFromEnd(&amp;quot;Hey! Bee🧶!&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;quot;Hey! Bee🧶!&amp;quot;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-remove-exclamation-marks-from-end&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve the next kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;while&quot;&gt;while-loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;replace&quot;&gt;replace&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;RegExp&quot;&gt;regex&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;regex101.com&#x2F;&quot;&gt;regex playground&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you like to solve katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;li&gt;Do you regularly use regex?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Count the number of characters in a string</title>
        <published>2020-07-10T00:00:00+00:00</published>
        <updated>2020-07-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-10/" type="text/html"/>
        <id>https://miku86.com/2020-07-10/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;I take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;548ef5b7f33a646ea50000b2&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;countAmountOfEachCharacter&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;inputString&lt;&#x2F;code&gt;, a valid string.&lt;&#x2F;p&gt;
&lt;p&gt;The function should return an object. The object has a key for every character that exists at least once in the string.
The value for each key is how many times that character exists in the string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: a string.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an object with keys for the existing characters and values for how many times that character exists in the string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;loop over the input string&lt;&#x2F;li&gt;
&lt;li&gt;if the character never has been seen before, add it to the object with a count of 1&lt;&#x2F;li&gt;
&lt;li&gt;if the character has been seen before, increase its count by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the object with every key-value pair&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;&amp;quot;bee&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Round 1: &lt;code&gt;{ &amp;quot;b&amp;quot;: 1 }&lt;&#x2F;code&gt; &#x2F;&#x2F; next character is &amp;quot;b&amp;quot;, which has never been seen before, therefore add it to the object with a count of 1&lt;&#x2F;li&gt;
&lt;li&gt;Round 2: &lt;code&gt;{ &amp;quot;b&amp;quot;: 1, &amp;quot;e&amp;quot;: 1 }&lt;&#x2F;code&gt; &#x2F;&#x2F; next character is &amp;quot;e&amp;quot;, which has never been seen before, therefore add it to the object with a count of 1&lt;&#x2F;li&gt;
&lt;li&gt;Round 3: &lt;code&gt;{ &amp;quot;b&amp;quot;: 1, &amp;quot;e&amp;quot;: 2 }&lt;&#x2F;code&gt; &#x2F;&#x2F; next character is &amp;quot;e&amp;quot;, which HAS been seen before, therefore increase its count by 1&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;{ &amp;quot;b&amp;quot;: 1, &amp;quot;e&amp;quot;: 2 }&lt;&#x2F;code&gt; &#x2F;&#x2F; return the object with every key-value pair&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function countAmountOfEachCharacter(inputString) {
  const returnObject = {};

  &amp;#x2F;&amp;#x2F; loop over input string
  for (let i = 0; i &amp;lt; inputString.length; i++) {
    &amp;#x2F;&amp;#x2F; check if character has been seen before
    if (returnObject.hasOwnProperty(inputString[i])) {
      &amp;#x2F;&amp;#x2F; increase its count by 1
      returnObject[inputString[i]] += 1;
    } else {
      &amp;#x2F;&amp;#x2F; add it to the object with a count of 1
      returnObject[inputString[i]] = 1;
    }
  }

  return returnObject;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(countAmountOfEachCharacter(&amp;quot;bee&amp;quot;));
&amp;#x2F;&amp;#x2F; { b: 1, e: 2 }

console.log(countAmountOfEachCharacter(&amp;quot;mississippi&amp;quot;));
&amp;#x2F;&amp;#x2F; { m: 1, i: 4, s: 4, p: 2 }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;warning&quot;&gt;Warning&lt;&#x2F;h2&gt;
&lt;p&gt;If you use emojis in your string, you should avoid the normal for-loop.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;@giltayar&#x2F;iterating-over-emoji-characters-the-es6-way-f06e4589516&quot;&gt;Explanation 1&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;44833008&#x2F;javascript-counting-frequency-of-emojis-in-text&quot;&gt;Explanation 2&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Thanks to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;benibela&quot;&gt;Benito van der Zander&lt;&#x2F;a&gt; for commenting!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-of-loop&quot;&gt;Implementation (for of-loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function countAmountOfEachCharacter(inputString) {
  const returnObject = {};

  &amp;#x2F;&amp;#x2F; loop over input string
  for (const character of inputString) {
    &amp;#x2F;&amp;#x2F; check if character has been seen before
    if (returnObject.hasOwnProperty(character)) {
      &amp;#x2F;&amp;#x2F; increase its count by 1
      returnObject[character] += 1;
    } else {
      &amp;#x2F;&amp;#x2F; add it to the object with a count of 1
      returnObject[character] = 1;
    }
  }

  return returnObject;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(countAmountOfEachCharacter(&amp;quot;bee&amp;quot;));
&amp;#x2F;&amp;#x2F; { b: 1, e: 2 }

console.log(countAmountOfEachCharacter(&amp;quot;mississippi&amp;quot;));
&amp;#x2F;&amp;#x2F; { m: 1, i: 4, s: 4, p: 2 }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (Functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function countAmountOfEachCharacter(inputString) {
  &amp;#x2F;&amp;#x2F; convert the string to an array
  return [...inputString].reduce(
    (accumulated, currentChar) =&amp;gt;
      &amp;#x2F;&amp;#x2F; check if character has been seen before
      accumulated.hasOwnProperty(currentChar)
        ? { ...accumulated, [currentChar]: accumulated[currentChar] + 1 } &amp;#x2F;&amp;#x2F; increase its count by 1
        : { ...accumulated, [currentChar]: 1 }, &amp;#x2F;&amp;#x2F; add it to the object with a count of 1
    {} &amp;#x2F;&amp;#x2F; start with an empty object
  );
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-2&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(countAmountOfEachCharacter(&amp;quot;bee&amp;quot;));
&amp;#x2F;&amp;#x2F; { b: 1, e: 2 }

console.log(countAmountOfEachCharacter(&amp;quot;mississippi&amp;quot;));
&amp;#x2F;&amp;#x2F; { m: 1, i: 4, s: 4, p: 2 }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-character-frequency&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve the next kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to read my latest stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;get in touch with me!&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for&quot;&gt;for-loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of-loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;Reduce&quot;&gt;reduce&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you like to solve katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Katas: Split a number array into odd and even numbers</title>
        <published>2020-07-09T00:00:00+00:00</published>
        <updated>2020-07-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-07-09/" type="text/html"/>
        <id>https://miku86.com/2020-07-09/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;Today, I start a new series about code katas.&lt;&#x2F;p&gt;
&lt;p&gt;I will take interesting katas of all levels and explain how to solve them.&lt;&#x2F;p&gt;
&lt;p&gt;Problem solving is an important skill, for your career and your life in general.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;d better learn to solve problems!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;source&quot;&gt;Source&lt;&#x2F;h2&gt;
&lt;p&gt;I take the ideas for the katas from different sources and re-write them.&lt;&#x2F;p&gt;
&lt;p&gt;Today&#x27;s source: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.codewars.com&#x2F;kata&#x2F;5721a78c283129e416000999&quot;&gt;Codewars&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;understanding-the-exercise-grey-exclama&quot;&gt;Understanding the Exercise ❗&lt;&#x2F;h2&gt;
&lt;p&gt;First, we need to understand the exercise!&lt;&#x2F;p&gt;
&lt;p&gt;This is a crucial part of (software) engineering.&lt;&#x2F;p&gt;
&lt;p&gt;Go over the exercise explanation again until you understand it 100%.&lt;&#x2F;p&gt;
&lt;p&gt;Do NOT try to save time here.&lt;&#x2F;p&gt;
&lt;p&gt;My method to do this:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Input: What do I put in?&lt;&#x2F;li&gt;
&lt;li&gt;Output: What do I want to get out?&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;today-s-exercise&quot;&gt;Today&#x27;s exercise&lt;&#x2F;h3&gt;
&lt;p&gt;Write a function &lt;code&gt;splitOddAndEven&lt;&#x2F;code&gt;, that accepts one parameter: &lt;code&gt;numbers&lt;&#x2F;code&gt;, an array of positive numbers.&lt;&#x2F;p&gt;
&lt;p&gt;The function should return an object with two arrays in it, one for all &lt;code&gt;odd&lt;&#x2F;code&gt; numbers and one for all &lt;code&gt;even&lt;&#x2F;code&gt; numbers.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Input: an array of numbers.&lt;&#x2F;p&gt;
&lt;p&gt;Output: an object with two arrays of numbers, one for the odd ones, one for the even ones.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thinking-about-the-solution-thought-balloon&quot;&gt;Thinking about the Solution 💭&lt;&#x2F;h2&gt;
&lt;p&gt;I think I understand the exercise (= what I put into the function and what I want to get out of it).&lt;&#x2F;p&gt;
&lt;p&gt;Now, I need the specific steps to get from input to output.&lt;&#x2F;p&gt;
&lt;p&gt;I try to do this in small baby steps.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;loop over the input array&lt;&#x2F;li&gt;
&lt;li&gt;if number is odd, save it in a variable &lt;code&gt;odd&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;if number is even, save it in a variable &lt;code&gt;even&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;return &lt;code&gt;odd&lt;&#x2F;code&gt; and &lt;code&gt;even&lt;&#x2F;code&gt; in an object&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;[1, 2, 3]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Round 1: &lt;code&gt;odd = [1]&lt;&#x2F;code&gt; &#x2F;&#x2F; first number in array is 1, which is odd, therefore goes into odd array&lt;&#x2F;li&gt;
&lt;li&gt;Round 2: &lt;code&gt;even = [2]&lt;&#x2F;code&gt; &#x2F;&#x2F; second number in array is 2, which is even, therefore goes into even array&lt;&#x2F;li&gt;
&lt;li&gt;Round 3: &lt;code&gt;odd = [1, 3]&lt;&#x2F;code&gt; &#x2F;&#x2F; third number in array is 3, which is odd, therefore goes into odd array, too&lt;&#x2F;li&gt;
&lt;li&gt;Output: &lt;code&gt;{ odd: [1, 3], even: [2] }&lt;&#x2F;code&gt; &#x2F;&#x2F; put odd array and even array in an object&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-loop&quot;&gt;Implementation (for loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function splitOddAndEven(numbers) {
  let odd = [];
  let even = [];

  for (let i = 0; i &amp;lt; numbers.length; i++) {
    if (numbers[i] % 2 === 0) {
      &amp;#x2F;&amp;#x2F; number is even
      even.push(numbers[i]);
    } else {
      &amp;#x2F;&amp;#x2F; number is not even (=odd)
      odd.push(numbers[i]);
    }
  }

  &amp;#x2F;&amp;#x2F; create an object with the odd and even array in it
  const returnObject = {
    odd,
    even,
  };

  return returnObject;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(splitOddAndEven([1, 2, 3]));
&amp;#x2F;&amp;#x2F; { odd: [ 1, 3 ], even: [ 2 ] }

console.log(splitOddAndEven([0, 3, 5]));
&amp;#x2F;&amp;#x2F; { odd: [ 3, 5 ], even: [ 0 ] }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-for-of-loop&quot;&gt;Implementation (for of-loop) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function splitOddAndEven(numbers) {
  let odd = [];
  let even = [];

  for (const number of numbers) {
    if (number % 2 === 0) {
      &amp;#x2F;&amp;#x2F; number is even
      even.push(number);
    } else {
      &amp;#x2F;&amp;#x2F; number is not even (=odd)
      odd.push(number);
    }
  }

  &amp;#x2F;&amp;#x2F; create an object with the odd and even array in it
  const returnObject = {
    odd,
    even,
  };

  return returnObject;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-1&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(splitOddAndEven([1, 2, 3]));
&amp;#x2F;&amp;#x2F; { odd: [ 1, 3 ], even: [ 2 ] }

console.log(splitOddAndEven([0, 3, 5]));
&amp;#x2F;&amp;#x2F; { odd: [ 3, 5 ], even: [ 0 ] }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-functional&quot;&gt;Implementation (Functional) ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;function splitOddAndEven(numbers) {
  &amp;#x2F;&amp;#x2F; filter out the odd numbers
  const odd = numbers.filter((number) =&amp;gt; number % 2 === 1);

  &amp;#x2F;&amp;#x2F; filter out the even numbers
  const even = numbers.filter((number) =&amp;gt; number % 2 === 0);

  &amp;#x2F;&amp;#x2F; create an object with the odd and even array in it
  const returnObject = {
    odd,
    even,
  };

  return returnObject;
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result-2&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(splitOddAndEven([1, 2, 3]));
&amp;#x2F;&amp;#x2F; { odd: [ 1, 3 ], even: [ 2 ] }

console.log(splitOddAndEven([0, 3, 5]));
&amp;#x2F;&amp;#x2F; { odd: [ 3, 5 ], even: [ 0 ] }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;playground-soccer&quot;&gt;Playground ⚽&lt;&#x2F;h2&gt;
&lt;p&gt;You can play around with the code &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;repl.it&#x2F;@miku86&#x2F;js-katas-odd-and-even-numbers&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Great work, mate!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll solve the next kata. Stay tuned!&lt;&#x2F;p&gt;
&lt;p&gt;If I should solve a specific kata, shoot me a message &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;forms.gle&#x2F;RmQLq7CLDiD2Ptmw5&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I would love to get in touch with you!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for&quot;&gt;for-loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;for of-loop&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;Array&#x2F;filter&quot;&gt;filter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you like to solve katas?&lt;&#x2F;li&gt;
&lt;li&gt;Which implementation do you like more? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Any alternative solution?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Recap</title>
        <published>2020-04-15T00:00:00+00:00</published>
        <updated>2020-04-15T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-04-15/" type="text/html"/>
        <id>https://miku86.com/2020-04-15/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-entries&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to get the whole entries (= all key-value pairs) of our Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll do a small recap of our Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-about-the-hash-table-thought-balloon&quot;&gt;Thoughts about the Hash Table 💭&lt;&#x2F;h2&gt;
&lt;p&gt;The Hash Table data structure is a very important concept, therefore most languages have (a variation of) a hash table built-in, e.g. JavaScript has an &lt;code&gt;object&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In our daily developer life we use &lt;code&gt;object&lt;&#x2F;code&gt; a lot, because it is an easy-to-grasp concept, that uses a (hopefully human-readable) key that is matched to a value, e.g. the key &lt;code&gt;name&lt;&#x2F;code&gt; is mapped to the value &lt;code&gt;miku86&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;In contrast to an array, we don&#x27;t have to know the index of a value, e.g. &lt;code&gt;person[1]&lt;&#x2F;code&gt;. Instead, we can simply use the human-readable key, e.g. &lt;code&gt;person.name&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;big-o&quot;&gt;Big O&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Remove: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As we can see, the Hash Table is very fast. Access, Insert and Remove need constant time to do their job, meaning an increase of the amount of data in the Hash Table doesn&#x27;t increase the time needed to do the job.&lt;&#x2F;p&gt;
&lt;p&gt;But be mindful of the fact, that these values heavily depend on the quality of our hash function.&lt;&#x2F;p&gt;
&lt;p&gt;If we &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;build a bad hash function&lt;&#x2F;a&gt; (like ours), that doesn&#x27;t distribute the key-value pairs very well, we&#x27;ll get a lot of &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-collisions&quot;&gt;collisions&lt;&#x2F;a&gt;, therefore our hash table could be very slow with a lot of data in it.&lt;&#x2F;p&gt;
&lt;p&gt;So you mostly want to use the built-in hash table of your language, instead of your own implementation, because the built-in one is well-optimized.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;final-implementation-memo&quot;&gt;Final Implementation 📝&lt;&#x2F;h2&gt;
&lt;p&gt;Our Hash Table has these methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;hash&lt;&#x2F;code&gt;: to create a hash for our key&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;set&lt;&#x2F;code&gt;: to add a key-value pair&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;get&lt;&#x2F;code&gt;: to get a specific key-value pair by using the key&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;keys&lt;&#x2F;code&gt;: to get all keys&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;values&lt;&#x2F;code&gt;: to get all values&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;entries&lt;&#x2F;code&gt;: to get all key-value pairs&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);
    this.size++;
  }

  get(key) {
    const hash = this.hash(key);

    if (this.data[hash]) {
      for (const item of this.data[hash]) {
        if (item[0] === key) {
          return item;
        }
      }
    }
  }

  keys() {
    const keys = [];

    for (let bucket of this.data) {
      if (bucket) {
        for (let item of bucket) {
          keys.push(item[0]);
        }
      }
    }

    return keys;
  }

  values() {
    const values = [];

    for (let bucket of this.data) {
      if (bucket) {
        for (let item of bucket) {
          values.push(item[1]);
        }
      }
    }

    return values;
  }

  entries() {
    const entries = [];

    for (let bucket of this.data) {
      if (bucket) {
        for (let item of bucket) {
          entries.push(item);
        }
      }
    }

    return entries;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you understand the concept?&lt;&#x2F;li&gt;
&lt;li&gt;Can you explain the concept to another person?&lt;&#x2F;li&gt;
&lt;li&gt;Can you implement the Hash Table on your own without looking at the code?&lt;&#x2F;li&gt;
&lt;li&gt;Can you think about the Big O of a Hash Table (without looking it up)?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-arrow-right&quot;&gt;Next ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;I hope you learned something about the concept of a Hash Table and tried your best to implement it on your own!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Which data structure should I cover next?&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Get all entries</title>
        <published>2020-04-14T00:00:00+00:00</published>
        <updated>2020-04-14T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-04-14/" type="text/html"/>
        <id>https://miku86.com/2020-04-14/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-values&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to get the values from our hash table.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to get the whole entries (= all key-value pairs) of our Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;requirements-thought-balloon&quot;&gt;Requirements 💭&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to get the values from our Hash Table:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method to get the entries (&lt;code&gt;entries&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-set&quot;&gt;the code with the &lt;code&gt;set&lt;&#x2F;code&gt; method&lt;&#x2F;a&gt;, so that we can use the &lt;code&gt;set&lt;&#x2F;code&gt; method to add some data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are not familiar with the hash function, &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;re-read this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;first, we declare an empty array for the entries&lt;&#x2F;li&gt;
&lt;li&gt;then we iterate over the data array&lt;&#x2F;li&gt;
&lt;li&gt;if there is data (= array of key-value pairs) at this specific index, iterate over this data (= the single key-value pairs)&lt;&#x2F;li&gt;
&lt;li&gt;add the data (= key-value pair) to the entries array&lt;&#x2F;li&gt;
&lt;li&gt;return the entries array&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As you can see, the steps are nearly the same as in our &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-keys&quot;&gt;&lt;code&gt;keys&lt;&#x2F;code&gt; function&lt;&#x2F;a&gt; and &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-values&quot;&gt;&lt;code&gt;values&lt;&#x2F;code&gt; function&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;We want to get all the entries.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
[
  [[&amp;quot;age&amp;quot;, 33]],
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
];

&amp;#x2F;&amp;#x2F; desired data:
[
  [&amp;quot;age&amp;quot;, 33],
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
  [&amp;quot;mean&amp;quot;, false],
];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;steps&quot;&gt;Steps&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
[
  [[&amp;quot;age&amp;quot;, 33]],
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
];

&amp;#x2F;&amp;#x2F; then we iterate over the data array
[[&amp;quot;age&amp;quot;, 33]];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;age&amp;quot;, 33];

&amp;#x2F;&amp;#x2F; add the data (= key-value pair) to the entries array
[[&amp;quot;age&amp;quot;, 33]];

&amp;#x2F;&amp;#x2F; then we iterate over the data array
[
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
  [&amp;quot;mean&amp;quot;, false],
];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];

&amp;#x2F;&amp;#x2F; add the data (= key-value pair) to the entries array
[
  [&amp;quot;age&amp;quot;, 33],
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;mean&amp;quot;, false];

&amp;#x2F;&amp;#x2F; add the data (= key-value pair) to the entries array
[
  [&amp;quot;age&amp;quot;, 33],
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
  [&amp;quot;mean&amp;quot;, false],
];

&amp;#x2F;&amp;#x2F; desired data:
[
  [&amp;quot;age&amp;quot;, 33],
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
  [&amp;quot;mean&amp;quot;, false],
];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Hash Table class
class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }

  entries() {
    &amp;#x2F;&amp;#x2F; declare an empty array for the entries
    const entries = [];

    &amp;#x2F;&amp;#x2F; iterate over the data array (I call a single array a &amp;quot;bucket&amp;quot;)
    for (let bucket of this.data) {
      &amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
      if (bucket) {
        &amp;#x2F;&amp;#x2F; iterate over this data (= the single key-value pairs)
        for (let item of bucket) {
          &amp;#x2F;&amp;#x2F; add the data (= key-value pair) to the entries array
          entries.push(item);
        }
      }
    }

    &amp;#x2F;&amp;#x2F; return the entries array
    return entries;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: I&#x27;m using a &lt;code&gt;for ... of&lt;&#x2F;code&gt;-loop. If you don&#x27;t know how this works, you can read about it on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;MDN&lt;&#x2F;a&gt;. You can use whatever you want to use, a default &lt;code&gt;for&lt;&#x2F;code&gt;-loop, a &lt;code&gt;for ... in&lt;&#x2F;code&gt;-loop, a functional approach etc.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create a new hash table
const newHashtable = new Hashtable();

&amp;#x2F;&amp;#x2F; add three new key-value pairs
newHashtable.set(&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;);
newHashtable.set(&amp;quot;mean&amp;quot;, false);
newHashtable.set(&amp;quot;age&amp;quot;, 33);

&amp;#x2F;&amp;#x2F; show the hash table data
console.log(newHashtable.data);
&amp;#x2F;&amp;#x2F; [ &amp;lt;301 empty items&amp;gt;, [ [ &amp;#x27;age&amp;#x27;, 33 ] ], &amp;lt;115 empty items&amp;gt;, [ [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ], [ &amp;#x27;mean&amp;#x27;, false ] ] ]

&amp;#x2F;&amp;#x2F; show the entries
console.log(newHashtable.entries());
&amp;#x2F;&amp;#x2F; [[&amp;#x27;age&amp;#x27;, 33], [&amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27;], [&amp;#x27;mean&amp;#x27;, false]] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We managed to write a function to get all entries, great work!&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, most of the logic was nearly the same as in our &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-keys&quot;&gt;&lt;code&gt;keys&lt;&#x2F;code&gt; function&lt;&#x2F;a&gt; and &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-values&quot;&gt;&lt;code&gt;values&lt;&#x2F;code&gt; function&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll recap the Hash Table!&lt;&#x2F;p&gt;
&lt;p&gt;Need some mentoring? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&quot;&gt;Click here&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How would you implement the &lt;code&gt;entries&lt;&#x2F;code&gt;-function?&lt;&#x2F;li&gt;
&lt;li&gt;Is there an alternative to our current approach, e.g. using already existing methods like &lt;code&gt;get&lt;&#x2F;code&gt;?&lt;&#x2F;li&gt;
&lt;li&gt;How would you write this code in a functional style?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Get values</title>
        <published>2020-04-13T00:00:00+00:00</published>
        <updated>2020-04-13T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-04-13/" type="text/html"/>
        <id>https://miku86.com/2020-04-13/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-keys&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to get the keys from our hash table.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to get the values of our Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;requirements-thought-balloon&quot;&gt;Requirements 💭&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to get the values from our Hash Table:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method to get the values (&lt;code&gt;values&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-set&quot;&gt;the code with the &lt;code&gt;set&lt;&#x2F;code&gt; method&lt;&#x2F;a&gt;, so that we can use the &lt;code&gt;set&lt;&#x2F;code&gt; method to add some data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are not familiar with the hash function, &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;re-read this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;first, we declare an empty array for the values&lt;&#x2F;li&gt;
&lt;li&gt;then we iterate over the data array&lt;&#x2F;li&gt;
&lt;li&gt;if there is data (= array of key-value pairs) at this specific index, iterate over this data (= the single key-value pairs)&lt;&#x2F;li&gt;
&lt;li&gt;add the data (= value) to the values array&lt;&#x2F;li&gt;
&lt;li&gt;return the values array&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As you can see, the steps are nearly the same as in our &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-keys&quot;&gt;last part&lt;&#x2F;a&gt;, where we got our keys.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;We want to get all the values.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
[
  [[&amp;quot;age&amp;quot;, 33]],
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
];

&amp;#x2F;&amp;#x2F; desired data:
[33, &amp;quot;miku86&amp;quot;, false];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;steps&quot;&gt;Steps&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
[
  [[&amp;quot;age&amp;quot;, 33]],
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
];

&amp;#x2F;&amp;#x2F; then we iterate over the data array
[[&amp;quot;age&amp;quot;, 33]];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;age&amp;quot;, 33];

&amp;#x2F;&amp;#x2F; add the data (= value) to the values array
[33];

&amp;#x2F;&amp;#x2F; then we iterate over the data array
[
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
  [&amp;quot;mean&amp;quot;, false],
];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];

&amp;#x2F;&amp;#x2F; add the data (= value) to the values array
[33, &amp;quot;miku86&amp;quot;];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;mean&amp;quot;, false];

&amp;#x2F;&amp;#x2F; add the data (= value) to the values array
[33, &amp;quot;miku86&amp;quot;, false];

&amp;#x2F;&amp;#x2F; desired data:
[33, &amp;quot;miku86&amp;quot;, false];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Hash Table class
class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }

  values() {
    &amp;#x2F;&amp;#x2F; declare an empty array for the values
    const values = [];

    &amp;#x2F;&amp;#x2F; iterate over the data array (I call a single array a &amp;quot;bucket&amp;quot;)
    for (let bucket of this.data) {
      &amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
      if (bucket) {
        &amp;#x2F;&amp;#x2F; iterate over this data (= the single key-value pairs)
        for (let item of bucket) {
          &amp;#x2F;&amp;#x2F; add the data (= value) to the values array
          values.push(item[1]);
        }
      }
    }

    &amp;#x2F;&amp;#x2F; return the values array
    return values;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: I&#x27;m using a &lt;code&gt;for ... of&lt;&#x2F;code&gt;-loop. If you don&#x27;t know how this works, you can read about it on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;MDN&lt;&#x2F;a&gt;. You can use whatever you want to use, a default &lt;code&gt;for&lt;&#x2F;code&gt;-loop, a &lt;code&gt;for ... in&lt;&#x2F;code&gt;-loop, a functional approach etc.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create a new hash table
const newHashtable = new Hashtable();

&amp;#x2F;&amp;#x2F; add three new key-value pairs
newHashtable.set(&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;);
newHashtable.set(&amp;quot;mean&amp;quot;, false);
newHashtable.set(&amp;quot;age&amp;quot;, 33);

&amp;#x2F;&amp;#x2F; show the hash table data
console.log(newHashtable.data);
&amp;#x2F;&amp;#x2F; [ &amp;lt;301 empty items&amp;gt;, [ [ &amp;#x27;age&amp;#x27;, 33 ] ], &amp;lt;115 empty items&amp;gt;, [ [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ], [ &amp;#x27;mean&amp;#x27;, false ] ] ]

&amp;#x2F;&amp;#x2F; show the values
console.log(newHashtable.values());
&amp;#x2F;&amp;#x2F; [ 33, &amp;#x27;miku86&amp;#x27;, false ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We managed to write a function to get all values, great work!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll learn how to get all key-value pairs (= entries) from our Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Need some mentoring? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&quot;&gt;Click here&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How would you implement the &lt;code&gt;values&lt;&#x2F;code&gt;-function?&lt;&#x2F;li&gt;
&lt;li&gt;How would you write this code in a functional style?&lt;&#x2F;li&gt;
&lt;li&gt;Should we remove duplicate values?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Get keys</title>
        <published>2020-04-12T00:00:00+00:00</published>
        <updated>2020-04-12T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-04-12/" type="text/html"/>
        <id>https://miku86.com/2020-04-12/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-get&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to get data from our hash table .&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to get the keys of our Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;requirements-thought-balloon&quot;&gt;Requirements 💭&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to get the keys from our Hash Table:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method to get the keys (&lt;code&gt;keys&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-set&quot;&gt;the code with the &lt;code&gt;set&lt;&#x2F;code&gt; method&lt;&#x2F;a&gt;, so that we can use the &lt;code&gt;set&lt;&#x2F;code&gt; method to add some data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are not familiar with the hash function, &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;re-read this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;first, we declare an empty array for the keys&lt;&#x2F;li&gt;
&lt;li&gt;then we iterate over the data array&lt;&#x2F;li&gt;
&lt;li&gt;if there is data (= array of key-value pairs) at this specific index, iterate over this data (= the single key-value pairs)&lt;&#x2F;li&gt;
&lt;li&gt;add the data (= key) to the keys array&lt;&#x2F;li&gt;
&lt;li&gt;return the keys array&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;We want to get all the keys.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
[
  [[&amp;quot;age&amp;quot;, 33]],
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
];

&amp;#x2F;&amp;#x2F; desired data:
[&amp;quot;age&amp;quot;, &amp;quot;name&amp;quot;, &amp;quot;mean&amp;quot;];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;steps&quot;&gt;Steps&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
[
  [[&amp;quot;age&amp;quot;, 33]],
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
];

&amp;#x2F;&amp;#x2F; then we iterate over the data array
[[&amp;quot;age&amp;quot;, 33]];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;age&amp;quot;, 33];

&amp;#x2F;&amp;#x2F; add the data (= key) to the keys array
[&amp;quot;age&amp;quot;];

&amp;#x2F;&amp;#x2F; then we iterate over the data array
[
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
  [&amp;quot;mean&amp;quot;, false],
];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];

&amp;#x2F;&amp;#x2F; add the data (= key) to the keys array
[&amp;quot;age&amp;quot;, &amp;quot;name&amp;quot;];

&amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
&amp;#x2F;&amp;#x2F; then iterate over this data (= the single key-value pairs)
[&amp;quot;mean&amp;quot;, false];

&amp;#x2F;&amp;#x2F; add the data (= key) to the keys array
[&amp;quot;age&amp;quot;, &amp;quot;name&amp;quot;, &amp;quot;mean&amp;quot;];

&amp;#x2F;&amp;#x2F; desired data:
[&amp;quot;age&amp;quot;, &amp;quot;name&amp;quot;, &amp;quot;mean&amp;quot;];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Hash Table class
class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }

  keys() {
    &amp;#x2F;&amp;#x2F; declare an empty array for the keys
    const keys = [];

    &amp;#x2F;&amp;#x2F; iterate over the data array (I call a single array a &amp;quot;bucket&amp;quot;)
    for (let bucket of this.data) {
      &amp;#x2F;&amp;#x2F; if there is data (= array of key-value pairs) at this specific index
      if (bucket) {
        &amp;#x2F;&amp;#x2F; iterate over this data (= the single key-value pairs)
        for (let item of bucket) {
          &amp;#x2F;&amp;#x2F; add the data (= key) to the keys array
          keys.push(item[0]);
        }
      }
    }

    &amp;#x2F;&amp;#x2F; return the keys array
    return keys;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: I&#x27;m using a &lt;code&gt;for ... of&lt;&#x2F;code&gt;-loop. If you don&#x27;t know how this works, you can read about it on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;MDN&lt;&#x2F;a&gt;. You can use whatever you want to use, a default &lt;code&gt;for&lt;&#x2F;code&gt;-loop, a &lt;code&gt;for ... in&lt;&#x2F;code&gt;-loop, a functional approach etc.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create a new hash table
const newHashtable = new Hashtable();

&amp;#x2F;&amp;#x2F; add three new key-value pairs
newHashtable.set(&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;);
newHashtable.set(&amp;quot;mean&amp;quot;, false);
newHashtable.set(&amp;quot;age&amp;quot;, 33);

&amp;#x2F;&amp;#x2F; show the hash table data
console.log(newHashtable.data);
&amp;#x2F;&amp;#x2F; [ &amp;lt;301 empty items&amp;gt;, [ [ &amp;#x27;age&amp;#x27;, 33 ] ], &amp;lt;115 empty items&amp;gt;, [ [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ], [ &amp;#x27;mean&amp;#x27;, false ] ] ]

&amp;#x2F;&amp;#x2F; show the keys
console.log(newHashtable.keys());
&amp;#x2F;&amp;#x2F; [ &amp;#x27;age&amp;#x27;, &amp;#x27;name&amp;#x27;, &amp;#x27;mean&amp;#x27; ] ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We managed to write a function to get all keys, great work!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll learn how to get all values from our Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Need some mentoring? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&quot;&gt;Click here&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How would you implement the &lt;code&gt;keys&lt;&#x2F;code&gt;-function?&lt;&#x2F;li&gt;
&lt;li&gt;How would you write this code in a functional style?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Get data</title>
        <published>2020-04-08T00:00:00+00:00</published>
        <updated>2020-04-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-04-08/" type="text/html"/>
        <id>https://miku86.com/2020-04-08/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-set&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to add data to our hash table .&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to get data out of our Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;requirements-thought-balloon&quot;&gt;Requirements 💭&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to get data from our Hash Table:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method to get data(&lt;code&gt;get&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;a key we want to search for (&lt;code&gt;key&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;a hash function to hash our &lt;code&gt;key&lt;&#x2F;code&gt; (&lt;code&gt;hash&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-set&quot;&gt;the code from the last lesson&lt;&#x2F;a&gt;, so that we can use the &lt;code&gt;set&lt;&#x2F;code&gt; method to add some data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are not familiar with the hash function, &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;re-read this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;first, we have to hash the key with our hash function&lt;&#x2F;li&gt;
&lt;li&gt;if there is data at this specific array index (= the hashed key), iterate over this data, search for the key and return the key-value pair&lt;&#x2F;li&gt;
&lt;li&gt;if there is data at this specific array index (= the hashed key), but not with our desired key, return null&lt;&#x2F;li&gt;
&lt;li&gt;if there is no data at the array index of the hashed key, return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;We want to get the key-value pair with the key &lt;code&gt;name&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
hashTableData = [
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
  [[&amp;quot;age&amp;quot;, 33]],
];

&amp;#x2F;&amp;#x2F; desired data:
[&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;steps&quot;&gt;Steps&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current hash table data:
hashTableData = [
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
    [&amp;quot;mean&amp;quot;, false],
  ],
  [[&amp;quot;age&amp;quot;, 33]],
];

&amp;#x2F;&amp;#x2F; we hash the key (= `name`) with our imaginary (!) hash function
0;

&amp;#x2F;&amp;#x2F; we go to the specific array index (= 0)
[
  [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;],
  [&amp;quot;mean&amp;quot;, false],
];

&amp;#x2F;&amp;#x2F; we go to the first key-value pair in this array
[&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];

&amp;#x2F;&amp;#x2F; this is the key (= &amp;quot;name&amp;quot;) we search for, therefore we return the key-value pair
[&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];

&amp;#x2F;&amp;#x2F; desired data:
[&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Hash Table class
class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    const hash = this.hash(key);

    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    this.data[hash].push([key, value]);

    this.size++;
  }

  get(key) {
    &amp;#x2F;&amp;#x2F; hash the key
    const hash = this.hash(key);

    &amp;#x2F;&amp;#x2F; look if there is any data at this specific array index
    if (this.data[hash]) {
      &amp;#x2F;&amp;#x2F; iterate over this data
      for (const item of this.data[hash]) {
        &amp;#x2F;&amp;#x2F; look if the first value of the array is the desired key, e.g. name
        if (item[0] === key) {
          &amp;#x2F;&amp;#x2F; if so, then return the key-value pair
          return item;
        }
      }
    }

    &amp;#x2F;&amp;#x2F; if there is no data at this specific array index
    &amp;#x2F;&amp;#x2F; OR if there is data, but not with the correct key
    &amp;#x2F;&amp;#x2F; then return null
    return null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: I&#x27;m using a &lt;code&gt;for ... of&lt;&#x2F;code&gt;-loop. If you don&#x27;t know how this works, you can read about it on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Statements&#x2F;for...of&quot;&gt;MDN&lt;&#x2F;a&gt;. You can use whatever you want to use, a default &lt;code&gt;for&lt;&#x2F;code&gt;-loop, a &lt;code&gt;for ... in&lt;&#x2F;code&gt;-loop, a functional approach etc.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create a new hash table
const newHashtable = new Hashtable();

&amp;#x2F;&amp;#x2F; add three new key-value pairs
newHashtable.set(&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;);
newHashtable.set(&amp;quot;mean&amp;quot;, false);
newHashtable.set(&amp;quot;age&amp;quot;, 33);
console.log(newHashtable.data);
&amp;#x2F;&amp;#x2F; [ &amp;lt;301 empty items&amp;gt;, [ [ &amp;#x27;age&amp;#x27;, 33 ] ], &amp;lt;115 empty items&amp;gt;, [ [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ], [ &amp;#x27;mean&amp;#x27;, false ] ] ]

console.log(newHashtable.get(&amp;quot;name&amp;quot;));
&amp;#x2F;&amp;#x2F; [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ] ✅

console.log(newHashtable.get(&amp;quot;mean&amp;quot;));
&amp;#x2F;&amp;#x2F; [ &amp;#x27;mean&amp;#x27;, false ] ✅

console.log(newHashtable.get(&amp;quot;age&amp;quot;));
&amp;#x2F;&amp;#x2F; [ &amp;#x27;age&amp;#x27;, 33 ] ✅

console.log(newHashtable.get(&amp;quot;nothing to see&amp;quot;));
&amp;#x2F;&amp;#x2F; null, because wrong array index ✅

console.log(newHashtable.get(&amp;quot;naem&amp;quot;));
&amp;#x2F;&amp;#x2F; null, because correct array index, but wrong key ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We managed to write a simple function that gets us our data, great work!&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll learn how to get all keys from our Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Need some mentoring? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&quot;&gt;Click here&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How would you implement the &lt;code&gt;get&lt;&#x2F;code&gt;-function?&lt;&#x2F;li&gt;
&lt;li&gt;How would you write this code in a functional style?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Add data</title>
        <published>2020-04-07T00:00:00+00:00</published>
        <updated>2020-04-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-04-07/" type="text/html"/>
        <id>https://miku86.com/2020-04-07/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-setup&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to setup our hash table .&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll use all of the stuff we learned so far to add data to our Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;requirements-thought-balloon&quot;&gt;Requirements 💭&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to add data to our Hash Table:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method to add data(&lt;code&gt;set&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;data we want to add (a &lt;code&gt;key&lt;&#x2F;code&gt;-&lt;code&gt;value&lt;&#x2F;code&gt;-pair)&lt;&#x2F;li&gt;
&lt;li&gt;a hash function to hash our &lt;code&gt;key&lt;&#x2F;code&gt; (&lt;code&gt;hash&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-setup&quot;&gt;the setup code that has the constructor and the hash function&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Hash Table class
class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  &amp;#x2F;&amp;#x2F; a hash function that inputs a key and outputs an array index
  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are not familiar with the hash function, &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;re-read this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;first, we have to hash the key with our hash function&lt;&#x2F;li&gt;
&lt;li&gt;if there is NO other key with this hash key: create an empty array at the correct position (= the hashed key), take the key-value-pair, add it &lt;code&gt;as an array&lt;&#x2F;code&gt; to the end of the created new array&lt;&#x2F;li&gt;
&lt;li&gt;if there already is a key with this hash: take the key-value-pair, add it &lt;code&gt;as an array&lt;&#x2F;code&gt; to the end of the existing array (separate chaining)&lt;&#x2F;li&gt;
&lt;li&gt;increase the Hash Table&#x27;s size by 1&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you are not familiar with separate chaining, &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-collisions&quot;&gt;re-read this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;if the hashed key is new, add a new empty array at this position; if the hashed key already exists, there will already be an array at this position, so no need to create a new one&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; currently empty hash table:
hashTableData = [];

&amp;#x2F;&amp;#x2F; desired hash table:
hashTableData = [
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;], &amp;#x2F;&amp;#x2F; array in array at index 0
  ],
];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; currently empty hash table:
hashTableData = [];

&amp;#x2F;&amp;#x2F; hash the key (= &amp;quot;name&amp;quot;) with our hash function: our imaginary (!) hash function outputs 0 as the hash key
&amp;#x2F;&amp;#x2F; there is NO other data at index 0 (currently no other key with this hash)
&amp;#x2F;&amp;#x2F; therefore we create an empty array at the correct position (= the hashed key)
hashTableData = [
  [], &amp;#x2F;&amp;#x2F; empty array at index 0 (because our imaginary hash function returned 0 as hash)
];

&amp;#x2F;&amp;#x2F; we take the key-value-pair and make it an array
newKeyValuePair = [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;];

&amp;#x2F;&amp;#x2F; we add the newKeyValuePair-array to the end of the newly created empty array
hashTableData = [
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;], &amp;#x2F;&amp;#x2F; newKeyValuePair from above
  ],
];

&amp;#x2F;&amp;#x2F; desired hash table:
hashTableData = [
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;], &amp;#x2F;&amp;#x2F; array in array at index 0
  ],
];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;p&gt;Array in Array in Array? 🤷&lt;&#x2F;p&gt;
&lt;p&gt;If we add a lot of data, there could be some hash collisions (duplicate results of the hashed key). We solve this by separate chaining. In our example, we can simply add a new key-value-pair after our current &lt;code&gt;newKeyValuePair&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;hashTableData = [
  [
    [&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;], &amp;#x2F;&amp;#x2F; array in array at index 0
    [&amp;quot;mean&amp;quot;, false], &amp;#x2F;&amp;#x2F; same hash, therefore same array index in parent array (= 0)
  ],
];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In theory, we wouldn&#x27;t need an array in array in array, if we only would have one key-value-pair at every index (= no collisions or using linear probing instead of separate chaining). But because our &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;custom hash function&lt;&#x2F;a&gt; is really bad and we want to learn the basics, we do it like this.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Hash Table class
class Hashtable {
  constructor() {
    this.data = [];
    this.size = 0;
  }

  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }

  set(key, value) {
    &amp;#x2F;&amp;#x2F; hash the key
    const hash = this.hash(key);

    &amp;#x2F;&amp;#x2F; if the hashed key is new, add a new empty array at this position
    &amp;#x2F;&amp;#x2F; if the hashed key already exists, there will already be an array at this position
    &amp;#x2F;&amp;#x2F; =&amp;gt; so no need to create a new one
    if (!this.data[hash]) {
      this.data[hash] = [];
    }

    &amp;#x2F;&amp;#x2F; save they key-value pair at the hashed array index
    this.data[hash].push([key, value]);

    &amp;#x2F;&amp;#x2F; increase the hash table&amp;#x27;s size by 1
    this.size++;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create a new hash table
const newHashtable = new Hashtable();

&amp;#x2F;&amp;#x2F; hash table should have no data and size 0
console.log(newHashtable);
&amp;#x2F;&amp;#x2F; Hashtable { data: [], size: 0 } ✅

&amp;#x2F;&amp;#x2F; add a new key-value pair
newHashtable.set(&amp;quot;name&amp;quot;, &amp;quot;miku86&amp;quot;);
console.log(newHashtable.data);
&amp;#x2F;&amp;#x2F; [ &amp;lt;417 empty items&amp;gt;, [ [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ] ] ]
&amp;#x2F;&amp;#x2F; the hash of &amp;#x27;name&amp;#x27; is 417, so it will go to array index 417, all indexes in front (0-416) will be empty

&amp;#x2F;&amp;#x2F; add a new key-value pair
newHashtable.set(&amp;quot;mean&amp;quot;, false);
console.log(newHashtable.data);
&amp;#x2F;&amp;#x2F; [ &amp;lt;417 empty items&amp;gt;, [ [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ], [ &amp;#x27;mean&amp;#x27;, false ] ] ]
&amp;#x2F;&amp;#x2F; &amp;#x27;name&amp;#x27; and &amp;#x27;mean&amp;#x27; have the same hash (417), so both go to index 417

&amp;#x2F;&amp;#x2F; add a new key-value pair
newHashtable.set(&amp;quot;age&amp;quot;, 33);
console.log(newHashtable.data);
&amp;#x2F;&amp;#x2F; [ &amp;lt;301 empty items&amp;gt;, [ [ &amp;#x27;age&amp;#x27;, 33 ] ], &amp;lt;115 empty items&amp;gt;, [ [ &amp;#x27;name&amp;#x27;, &amp;#x27;miku86&amp;#x27; ], [ &amp;#x27;mean&amp;#x27;, false ] ] ]
&amp;#x2F;&amp;#x2F; &amp;#x27;age&amp;#x27; has hash 301, so goes to index 301.
&amp;#x2F;&amp;#x2F; &amp;#x27;name&amp;#x27; and &amp;#x27;mean&amp;#x27; go to index 417, therefore there is a gap from 302 to 416, so 115 empty items
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;Wow, a lot of explanations after our longer break!&lt;&#x2F;p&gt;
&lt;p&gt;Great work if you made it to the end.&lt;&#x2F;p&gt;
&lt;p&gt;Next time, we&#x27;ll learn how to get data from our Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Need some mentoring? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&quot;&gt;Click here&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How would you implement the &lt;code&gt;set&lt;&#x2F;code&gt;-function?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Setup</title>
        <published>2020-02-20T00:00:01.001+00:00</published>
        <updated>2020-02-20T00:00:01.001+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-02-20/" type="text/html"/>
        <id>https://miku86.com/2020-02-20/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-collisions&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to handle hash collisions.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll use all of the stuff we learned so far to setup our Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;requirements-thought-balloon&quot;&gt;Requirements 💭&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to setup our Hash Table:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a Hash Table class&lt;&#x2F;li&gt;
&lt;li&gt;a container for our data&lt;&#x2F;li&gt;
&lt;li&gt;the size of the data&lt;&#x2F;li&gt;
&lt;li&gt;a hash function that inputs a key and outputs an array index&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation ⛑&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Hash Table class
class Hashtable {
  constructor() {
    &amp;#x2F;&amp;#x2F; a container for our data
    this.data = [];

    &amp;#x2F;&amp;#x2F; the size of the data
    this.size = 0;
  }

  &amp;#x2F;&amp;#x2F; a hash function that inputs a key and outputs an array index
  hash(key) {
    const chars = key.split(&amp;quot;&amp;quot;);
    const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
    const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
    return charCodeSum;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are not familiar with the hash function, &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;re-read this post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create a new hash table
const newHashtable = new Hashtable();

&amp;#x2F;&amp;#x2F; hash table should have no data and size 0
console.log(newHashtable);
&amp;#x2F;&amp;#x2F; Hashtable { data: [], size: 0 } ✅
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We&#x27;ll learn how to add data to our Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Need some mentoring? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&quot;&gt;Click here&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;How would you implement the Hash Table?&lt;&#x2F;li&gt;
&lt;li&gt;How would you build the hash function? Why?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Collisions</title>
        <published>2020-02-19T00:00:00+00:00</published>
        <updated>2020-02-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-02-19/" type="text/html"/>
        <id>https://miku86.com/2020-02-19/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned what a Hash Function is and how to write a simple one.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to handle collisions.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;problem-pensive&quot;&gt;Problem 😔&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s modify our old example.
We write a friends application and want to save their &lt;code&gt;name&lt;&#x2F;code&gt; and if they are &lt;code&gt;mean&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const friend = {
  name: &amp;quot;Peter&amp;quot;,
  mean: false,
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We use our &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-hash-function&quot;&gt;selfmade (and bad) hash function&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const hash = (key) =&amp;gt; {
  const chars = key.split(&amp;quot;&amp;quot;);
  const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());
  const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);
  return charCodeSum;
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Result:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;hash(&amp;quot;name&amp;quot;); &amp;#x2F;&amp;#x2F; 417
hash(&amp;quot;mean&amp;quot;); &amp;#x2F;&amp;#x2F; 417
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Shit. Two different keys have the same hash and therefore would get stored to the same index &lt;code&gt;417&lt;&#x2F;code&gt; of our array.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;solution-disappoin&quot;&gt;Solution 😌&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s think about a real-life problem.&lt;&#x2F;p&gt;
&lt;p&gt;We go to the cinema and buy two tickets, I get seat &lt;code&gt;417&lt;&#x2F;code&gt;, you also get seat &lt;code&gt;417&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;How would we solve this seat collision without going back to the ticket seller?&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Separate Chaining: Because the seat is really big, we can share the same seat.&lt;&#x2F;li&gt;
&lt;li&gt;Linear Probing &#x2F; Open Addressing: One of us takes seat &lt;code&gt;417&lt;&#x2F;code&gt;, the other one takes the next free seat, e.g. &lt;code&gt;418&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;separate-chaining-chains&quot;&gt;Separate Chaining ⛓&lt;&#x2F;h3&gt;
&lt;p&gt;If we get the same hash, we store our data at the same index, but chained in a new data structure, e.g. another array.&lt;&#x2F;p&gt;
&lt;p&gt;Storing:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;We hash &lt;code&gt;name&lt;&#x2F;code&gt; and get index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We store &lt;code&gt;[&amp;quot;name&amp;quot;, &amp;quot;Peter&amp;quot;]&lt;&#x2F;code&gt; at index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We hash &lt;code&gt;mean&lt;&#x2F;code&gt; and get index &lt;code&gt;417&lt;&#x2F;code&gt;, too&lt;&#x2F;li&gt;
&lt;li&gt;Because this array item is already filled with &lt;code&gt;[&amp;quot;name&amp;quot;, &amp;quot;Peter&amp;quot;]&lt;&#x2F;code&gt;, we create a new array around the existing item&lt;&#x2F;li&gt;
&lt;li&gt;We add &lt;code&gt;[&amp;quot;mean&amp;quot;, false]&lt;&#x2F;code&gt; into the existing array at index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Result: an array in an array: &lt;code&gt;[ [&amp;quot;name&amp;quot;, &amp;quot;Peter&amp;quot;], [&amp;quot;mean&amp;quot;, false] ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Searching &lt;code&gt;mean&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;We hash it and get index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We look at index &lt;code&gt;417&lt;&#x2F;code&gt;: &lt;code&gt;[ [&amp;quot;name&amp;quot;, &amp;quot;Peter&amp;quot;], [&amp;quot;mean&amp;quot;, false] ]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We iterate over this array until we find &lt;code&gt;mean&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;linear-probing-open-addressing-blue&quot;&gt;Linear Probing &#x2F; Open Addressing 📖&lt;&#x2F;h3&gt;
&lt;p&gt;If we get the same hash, we search for the next empty array index.&lt;&#x2F;p&gt;
&lt;p&gt;Storing:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;We hash &lt;code&gt;name&lt;&#x2F;code&gt; and get index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We store &lt;code&gt;[&amp;quot;name&amp;quot;, &amp;quot;Peter&amp;quot;]&lt;&#x2F;code&gt; at index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We hash &lt;code&gt;mean&lt;&#x2F;code&gt; and get index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Because this array item is already filled with &lt;code&gt;[&amp;quot;name&amp;quot;, &amp;quot;Peter&amp;quot;]&lt;&#x2F;code&gt;, we search for the next empty index, e.g. &lt;code&gt;418&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We store &lt;code&gt;[&amp;quot;mean&amp;quot;, false]&lt;&#x2F;code&gt; at index &lt;code&gt;418&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Searching &lt;code&gt;mean&lt;&#x2F;code&gt;:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;We hash it, get index &lt;code&gt;417&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;We look at index &lt;code&gt;417&lt;&#x2F;code&gt;: &lt;code&gt;[&amp;quot;name&amp;quot;, &amp;quot;Peter&amp;quot;]&lt;&#x2F;code&gt;, but that&#x27;s not the data we want&lt;&#x2F;li&gt;
&lt;li&gt;We go to the next array item at index &lt;code&gt;418&lt;&#x2F;code&gt; and there is our &lt;code&gt;[&amp;quot;mean&amp;quot;, false]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Note: This example uses &lt;em&gt;linear&lt;&#x2F;em&gt; probing, meaning steps are fixed, e.g. we increase the index by 1 when we search for a next free index. Open Addressing is a broader term for this method, you can read about it &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table#Open_addressing&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;why-we-don-t-want-to-have-collisions-thought-balloon&quot;&gt;Why we don&#x27;t want to have collisions 💭&lt;&#x2F;h3&gt;
&lt;p&gt;With both methods of handling the collision, Separate Chaining and Linear Probing, we would have to iterate over stored data and check if this is our desired data. The more collisions we have, the bigger the data to iterate over, the longer it takes to find our data.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We managed to learn the theory, great work! We will start to implement our Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Need some mentoring? &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;mentoring&quot;&gt;Click here&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table#Separate_chaining&quot;&gt;Wikipedia: Separate Chaining&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table#Open_addressing&quot;&gt;Wikipedia: Open Addressing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Linear_probing&quot;&gt;Wikipedia: Linear Probing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Which method for handling collisions is easier to implement?&lt;&#x2F;li&gt;
&lt;li&gt;Which method would you use? Why?&lt;&#x2F;li&gt;
&lt;li&gt;What are the (dis)advantages of both methods?&lt;&#x2F;li&gt;
&lt;li&gt;Can you come up with other methods to handle collisions?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Hash Function</title>
        <published>2020-02-18T00:00:00+00:00</published>
        <updated>2020-02-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-02-18/" type="text/html"/>
        <id>https://miku86.com/2020-02-18/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-hash-table-intro&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned what a Hash Table is and why we want to use it.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to write a simple Hash Function.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;problem-why-do-we-need-a-hash-function&quot;&gt;Problem: WHY do we need a Hash Function?&lt;&#x2F;h2&gt;
&lt;p&gt;To access a value in an array, we need its index.&lt;&#x2F;p&gt;
&lt;p&gt;But we want to use our Hash Table with a key instead of an index, e.g. &lt;code&gt;user.name&lt;&#x2F;code&gt; instead of &lt;code&gt;user[0]&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;To convert the index to a key, we need a helper function that does this task for us.&lt;&#x2F;p&gt;
&lt;p&gt;This is where the hash functions comes into play.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-a-hash-function&quot;&gt;What is a Hash Function? ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;For our Hash Table, we need a function, that converts a key into an array index.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s use the example from the last post.&lt;&#x2F;p&gt;
&lt;p&gt;I want to build something like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const user = {
  name: &amp;quot;miku86&amp;quot;,
  homeCountry: &amp;quot;Germany&amp;quot;,
  age: 33,
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Because we want to use an array under the hood, the implementation could look like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const user = [33, &amp;quot;miku86&amp;quot;, &amp;quot;Germany&amp;quot;];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;So when we want to get the correct index of:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;name&lt;&#x2F;code&gt;, we want to run &lt;code&gt;myHashFunction(&amp;quot;name&amp;quot;)&lt;&#x2F;code&gt; and get back &lt;code&gt;1&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;homeCountry&lt;&#x2F;code&gt;, we want to run &lt;code&gt;myHashFunction(&amp;quot;homeCountry&amp;quot;)&lt;&#x2F;code&gt; and get back &lt;code&gt;2&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;age&lt;&#x2F;code&gt;, we want to run &lt;code&gt;myHashFunction(&amp;quot;age&amp;quot;)&lt;&#x2F;code&gt; and get back &lt;code&gt;0&lt;&#x2F;code&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;As you can see, there is no order in the array, the array index is solely bound to the key.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s think about the hash function&#x27;s constraints:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Deterministic&lt;&#x2F;strong&gt;: Anytime we input the same key, we should get back the same array index, otherwise we won&#x27;t find our value, because our data doesn&#x27;t change its place in the array.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Fast&lt;&#x2F;strong&gt;: We need to use the hash function every time we read, create, update, delete data, therefore it should be fast and shouldn&#x27;t be connected to the length of the existing data (&lt;code&gt;O(1)&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Uniform Distribution&lt;&#x2F;strong&gt;: Think about an array of length 2. If we want to add 3 values to an array with 2 places to store data, we would have to store 2 values in 1 place (or lose data (we don&#x27;t want to do that)). This would be a &lt;strong&gt;collision&lt;&#x2F;strong&gt;, meaning two values live at one place. Because collisions lead to additional computational work (we have to find the desired value), we want an uniform distribution of our array indexes.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;how-do-we-build-a-hash-function&quot;&gt;How do we build a Hash Function? 🛠&lt;&#x2F;h2&gt;
&lt;p&gt;There are a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;List_of_hash_functions&quot;&gt;lot of hash functions&lt;&#x2F;a&gt; out there. Because we want to learn about the bigger concepts, our hash function will be far (really far) away from being good.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;version-1-length-of-the-key&quot;&gt;Version 1: length of the key&lt;&#x2F;h3&gt;
&lt;p&gt;Let&#x27;s be creative and think about a simple hash function, that could probably work, let&#x27;s take the length of our key.&lt;&#x2F;p&gt;
&lt;p&gt;The length of:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;name&lt;&#x2F;code&gt; is 4&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;homeCountry&lt;&#x2F;code&gt; is 11&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;age&lt;&#x2F;code&gt; is&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This works for this small example. But as you can guess, there is a high probability that this will lead to collisions very quickly. If we increase the amount of our key-value pairs to 100 instead of 3, we would end up with an array that has a lot of collisions between index ~3 and 10, because most (english) words are fairly short in length, so many keys would get the same hash.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;version-2-sum-of-character-codes-of-the-key&quot;&gt;Version 2: sum of character codes of the key&lt;&#x2F;h3&gt;
&lt;p&gt;Every character has a UTF-16 code. JavaScript has a function to get this value, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;String&#x2F;charCodeAt&quot;&gt;&lt;code&gt;charCodeAt&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Example: &lt;code&gt;name&lt;&#x2F;code&gt; has the charcodes:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;n: &lt;code&gt;110&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;a: &lt;code&gt;97&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;m: &lt;code&gt;109&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;e: &lt;code&gt;101&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If we sum these charcodes, we get &lt;code&gt;417&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;implementation-of-our-simple-but-not-so-good-hash-function&quot;&gt;Implementation of our simple (but not-so-good) hash function&lt;&#x2F;h3&gt;
&lt;p&gt;Our tasks:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;split the key into its characters: &lt;code&gt;name&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;n&lt;&#x2F;code&gt;,&lt;code&gt;a&lt;&#x2F;code&gt;, &lt;code&gt;m&lt;&#x2F;code&gt;, &lt;code&gt;e&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;convert every character into its character code: n: &lt;code&gt;110&lt;&#x2F;code&gt;, a: &lt;code&gt;97&lt;&#x2F;code&gt;, m: &lt;code&gt;109&lt;&#x2F;code&gt;, e: &lt;code&gt;101&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;sum all character codes: 110 + 97 + 109 + 101 =&amp;gt; 417&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const hash = (key) =&amp;gt; {
  &amp;#x2F;&amp;#x2F; split the key into its characters
  const chars = key.split(&amp;quot;&amp;quot;);

  &amp;#x2F;&amp;#x2F; convert every character into its character code
  const charCodes = chars.map((char) =&amp;gt; char.charCodeAt());

  &amp;#x2F;&amp;#x2F; sum all character codes
  const charCodeSum = charCodes.reduce((acc, cur) =&amp;gt; acc + cur);

  &amp;#x2F;&amp;#x2F; return the sum
  return charCodeSum;
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Result:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;hash(&amp;quot;name&amp;quot;);
&amp;#x2F;&amp;#x2F; 417
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;We created a simple hash function to grasp the concept.&lt;&#x2F;p&gt;
&lt;p&gt;The hash function takes a key as input and returns the array index where it should get saved.&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, hash functions are a very complex topic. If you want to dive deeper into it, I invite you to read the &lt;code&gt;Further Reading&lt;&#x2F;code&gt; section.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We will learn how to handle collisions.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t miss interesting stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;go to&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_function&quot;&gt;Simple Wiki: Hash Function&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_function&quot;&gt;Wikipedia: Hash Function&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables#Choosing_a_good_hash_function&quot;&gt;Wikibooks: Hash Function&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;List_of_hash_functions&quot;&gt;Wikipedia: List of Hash Functions&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What&#x27;s the easiest method to generate a collision with our hash function?&lt;&#x2F;li&gt;
&lt;li&gt;How can we improve our hash function?&lt;&#x2F;li&gt;
&lt;li&gt;What are the advantages of our implemented hash function?&lt;&#x2F;li&gt;
&lt;li&gt;What are the disadvantages of our implemented hash function?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Hash Table: Intro</title>
        <published>2020-02-17T00:00:00+00:00</published>
        <updated>2020-02-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-02-17/" type="text/html"/>
        <id>https://miku86.com/2020-02-17/</id>
        
        <content type="html">&lt;h2 id=&quot;intro-globe-with-meridians&quot;&gt;Intro 🌐&lt;&#x2F;h2&gt;
&lt;p&gt;After we finished the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-intro&quot;&gt;small series about the Queue&lt;&#x2F;a&gt; and &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-recap-lists-stack-queue&quot;&gt;compared our linear data structures&lt;&#x2F;a&gt;, we start with the Hash Table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;problem-why-do-we-need-a-hash-table&quot;&gt;Problem: WHY do we need a Hash Table?&lt;&#x2F;h2&gt;
&lt;p&gt;If we want to store user data, we could use an array, e.g.:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const user = [&amp;quot;miku86&amp;quot;, &amp;quot;Germany&amp;quot;, 33];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This works, but it could be hard to understand.&lt;&#x2F;p&gt;
&lt;p&gt;The first value could be my name,
the second one could be my home country (are you sure?),
but what is the meaning of the third one?&lt;&#x2F;p&gt;
&lt;p&gt;A lot of guessing here, because we don&#x27;t have a lot of context.
The second element could have various meanings,
e.g. my home country, my current location, my favorite country to travel to or the best soccer team in the world.&lt;&#x2F;p&gt;
&lt;p&gt;It would be awesome, if we could give every value a context, e.g.:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const user = {
  name: &amp;quot;miku86&amp;quot;,
  homeCountry: &amp;quot;Germany&amp;quot;,
  age: 33,
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a data structure that gives every value a context.
Each &lt;code&gt;value&lt;&#x2F;code&gt; has a context, because each has a &lt;code&gt;key&lt;&#x2F;code&gt; that is human-readable.&lt;&#x2F;p&gt;
&lt;p&gt;If you did some JavaScript stuff, you&#x27;ve already seen this data structure,
JavaScript calls it an &lt;code&gt;object&lt;&#x2F;code&gt;, the broader term is &lt;strong&gt;Hash Table&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-a-hash-table&quot;&gt;What is a Hash Table? ▶️&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;most languages have (a variation of) a hash table built-in&lt;&#x2F;li&gt;
&lt;li&gt;Example: &lt;code&gt;object&lt;&#x2F;code&gt; (JavaScript) or &lt;code&gt;Dictionary&lt;&#x2F;code&gt; (Python)&lt;&#x2F;li&gt;
&lt;li&gt;each data entry has a (human-readable) key that is matched to a value, e.g. the key &lt;code&gt;name&lt;&#x2F;code&gt; is matched to the value &lt;code&gt;miku86&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;keys are not ordered&lt;&#x2F;li&gt;
&lt;li&gt;fast: search, add, remove&lt;&#x2F;li&gt;
&lt;li&gt;because we use a hash function (explanation later), it is called a &lt;strong&gt;Hash Table&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;how-do-we-build-a-hash-table-without-using-the-built-in-object&quot;&gt;How do we build a Hash Table (without using the built-in &lt;code&gt;object&lt;&#x2F;code&gt;)? 🛠&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;we&#x27;ll use an array&lt;&#x2F;li&gt;
&lt;li&gt;we want to find a value by using its key, e.g. &lt;code&gt;user.name =&amp;gt; &amp;quot;miku86&amp;quot;&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;to find an array index by using a key, we have to connect a &lt;code&gt;key&lt;&#x2F;code&gt; to an &lt;code&gt;index&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;to convert a human-readable &lt;code&gt;key&lt;&#x2F;code&gt; into an array index, we use a &lt;strong&gt;hash function&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;li&gt;because we use a hash function, the data structure is called &lt;strong&gt;Hash Table&lt;&#x2F;strong&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s use the example from above:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const user = {
  name: &amp;quot;miku86&amp;quot;,
  homeCountry: &amp;quot;Germany&amp;quot;,
  age: 33,
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We want to get my name value by using the key &lt;code&gt;name&lt;&#x2F;code&gt;.
Because we want to use an array under the hood, we should think about it like that:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const user = [&amp;quot;miku86&amp;quot;, &amp;quot;Germany&amp;quot;, 33];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We have 3 array items, each array item has exactly one value in it, e.g. the array item with index 0 has the value &#x27;miku86&#x27;.&lt;&#x2F;p&gt;
&lt;p&gt;So to access the correct value, we always have to know the correct array index.&lt;&#x2F;p&gt;
&lt;p&gt;But we don&#x27;t want to work with the index, we want to work with the key, e.g. &lt;code&gt;name&lt;&#x2F;code&gt;, there even isn&#x27;t a key 🤷&lt;&#x2F;p&gt;
&lt;p&gt;We need a function that takes our key, e.g. &lt;code&gt;name&lt;&#x2F;code&gt;, and converts it into the correct index of the array item our value lives in, e.g. &lt;code&gt;0&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;This is where the hash functions comes into play.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We will learn how to build our own simple hash function for the Hash Table.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t miss interesting stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;go to&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Simple Wiki: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Hash_table&quot;&gt;Wikipedia: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Hash_Tables&quot;&gt;Wikibooks: Hash Table&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Did you understand the concept?&lt;&#x2F;li&gt;
&lt;li&gt;Can you explain the concept to another person?&lt;&#x2F;li&gt;
&lt;li&gt;Can you think about the Big O of a Hash Table (without looking it up)?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Git: Delete merged branches</title>
        <published>2020-01-10T00:00:00+00:00</published>
        <updated>2020-01-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-01-10/" type="text/html"/>
        <id>https://miku86.com/2020-01-10/</id>
        
        <content type="html">&lt;h2 id=&quot;problem&quot;&gt;Problem&lt;&#x2F;h2&gt;
&lt;p&gt;I build an app and use git branches.&lt;&#x2F;p&gt;
&lt;p&gt;Branches sum up, I don&#x27;t know which branches are already merged into master and I lose overview.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;git branch&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;solution-linux&quot;&gt;Solution (Linux)&lt;&#x2F;h2&gt;
&lt;p&gt;I need a command that checks if a branch is merged into master and if it is merged, it should get deleted locally.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git checkout master&lt;&#x2F;code&gt; (or whatever branch you want to compare to)&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git branch --merged | egrep -v &amp;quot;(^\*|master|dev)&amp;quot; | xargs git branch -d&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h2 id=&quot;explanation&quot;&gt;Explanation&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;git branch --merged&lt;&#x2F;code&gt;: List all branches whose tips are reachable from the specified commit (HEAD if not specified).&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;egrep -v &amp;quot;(^\*|master|dev)&amp;quot;&lt;&#x2F;code&gt;: Search for all lines that do not start with &lt;code&gt;*&lt;&#x2F;code&gt; (= the current branch), or don&#x27;t have &lt;code&gt;master&lt;&#x2F;code&gt; or &lt;code&gt;dev&lt;&#x2F;code&gt; in it.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;xargs git branch -d&lt;&#x2F;code&gt;: Execute the command to delete all found branches from step 2.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;6127328&#x2F;how-can-i-delete-all-git-branches-which-have-been-merged&quot;&gt;Stackoverflow&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;6127884&quot;&gt;Windows: read the comments &lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Recap: Lists, Stack, Queue</title>
        <published>2020-01-09T00:00:00+00:00</published>
        <updated>2020-01-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-01-09/" type="text/html"/>
        <id>https://miku86.com/2020-01-09/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-recap&quot;&gt;Last time&lt;&#x2F;a&gt;, we made a recap of the Queue data structure.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we want to make a recap about all our learned data structure so far.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;our-data-structures&quot;&gt;Our Data Structures&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-intro&quot;&gt;Singly Linked List&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-intro&quot;&gt;Doubly Linked List&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-intro&quot;&gt;Stack&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-intro&quot;&gt;Queue&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All of these data structures are linear, meaning its elements are connected in a sequence and we can traverse the whole data structure in a single run.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;singly-linked-list&quot;&gt;Singly Linked List&lt;&#x2F;h3&gt;
&lt;p&gt;We started with the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-intro&quot;&gt;Singly Linked List&lt;&#x2F;a&gt;. This was our longest series of 11 lessons, because usually it takes most of the time to understand some basic concepts, e.g. what &amp;quot;linked&amp;quot; means, how a node works and which methods our data structure needs. Every element in a Singly Linked List has a pointer to its next node.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;doubly-linked-list&quot;&gt;Doubly Linked List&lt;&#x2F;h3&gt;
&lt;p&gt;After we&#x27;ve &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-recap&quot;&gt;finished the Singly Linked List&lt;&#x2F;a&gt;, we learned about the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-intro&quot;&gt;Doubly Linked List&lt;&#x2F;a&gt; in a series of 10 lessons. Because we already had some insights about the concepts of a Singly Linked List, it became easier to understand the concepts, to learn about the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-recap#thoughts-about-the-doubly-linked-list&quot;&gt;Pros and Cons of a Doubly Linked List&lt;&#x2F;a&gt; and to implement it. Every element in a Doubly Linked List has a pointer to its next node &lt;em&gt;and&lt;&#x2F;em&gt; to its previous node.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;stack&quot;&gt;Stack&lt;&#x2F;h3&gt;
&lt;p&gt;After we&#x27;ve &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-recap&quot;&gt;finished the Doubly Linked List&lt;&#x2F;a&gt;, we had some solid fundamentals to &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-intro&quot;&gt;start with the Stack&lt;&#x2F;a&gt; and to learn about its &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-recap#thoughts-about-the-stack&quot;&gt;&amp;quot;Last In, First Out&amp;quot;-Principle&lt;&#x2F;a&gt;, e.g. when we have a deck of cards.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;queue&quot;&gt;Queue&lt;&#x2F;h3&gt;
&lt;p&gt;After we&#x27;ve &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-recap&quot;&gt;finished the Stack&lt;&#x2F;a&gt;, we &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-intro&quot;&gt;started with the Queue&lt;&#x2F;a&gt; and learned about its &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-recap#thoughts-about-the-queue-&quot;&gt;&amp;quot;First In, First Out&amp;quot;-Principle&lt;&#x2F;a&gt;, e.g. when we stand in line in a store.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;big-o&quot;&gt;Big O&lt;&#x2F;h2&gt;
&lt;p&gt;All of our 4 data structures have the same Big O values.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.bigocheatsheet.com&#x2F;&quot;&gt;Source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Linked_list#Singly_linked_list&quot;&gt;Wikipedia: Singly Linked List&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Doubly_linked_list&quot;&gt;Wikipedia: Doubly Linked List&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stack_(abstract_data_type)&quot;&gt;Wikipedia: Stack&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Queue_(abstract_data_type)&quot;&gt;Wikipedia: Queue&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;List_of_data_structures#Linear_data_structures&quot;&gt;Wikipedia: Other Linear Data Structures&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What additional data structure are you interested in?&lt;&#x2F;li&gt;
&lt;li&gt;Can you think about additional methods for our data structures?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We will start with a new data structure!&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t miss interesting stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Queue: Recap</title>
        <published>2020-01-04T00:00:00+00:00</published>
        <updated>2020-01-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-01-04/" type="text/html"/>
        <id>https://miku86.com/2020-01-04/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-dequeue&quot;&gt;Last time&lt;&#x2F;a&gt;, we added the &lt;code&gt;dequeue&lt;&#x2F;code&gt; method.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you learned something about the concept of a Queue and tried your best to implement it on your own.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;thoughts-about-the-queue-thought-balloon&quot;&gt;Thoughts about the Queue 💭&lt;&#x2F;h3&gt;
&lt;p&gt;We implemented the Queue using a &lt;a href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;2020-01-04&#x2F;js-ds-singly-linked-list-intro&quot;&gt;Singly Linked List&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The Queue data structure is a very important concept, because we use it all the time.&lt;&#x2F;p&gt;
&lt;p&gt;The Queue is based on the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;FIFO_(computing_and_electronics)&quot;&gt;&amp;quot;First In, First Out&amp;quot;-Principle&lt;&#x2F;a&gt;, meaning the first node that goes into the queue will later be the first node, that goes out of the queue.&lt;&#x2F;p&gt;
&lt;p&gt;Examples in real life: people who want to pay in a store, the tasks of a printer.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Remove: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;final-implementation-memo&quot;&gt;Final Implementation 📝&lt;&#x2F;h2&gt;
&lt;p&gt;Our Queue has these methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;enqueue&lt;&#x2F;code&gt;, to add a node to the end of the queue&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;dequeue&lt;&#x2F;code&gt;, to remove a node from the start of the queue&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Queue {
  constructor() {
    this.length = 0;
    this.start = null;
    this.end = null;
  }

  enqueue(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.start = newNode;
      this.end = newNode;
    } else {
      this.end.next = newNode;
      this.end = newNode;
    }

    this.length += 1;
    return newNode;
  }

  dequeue() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.start;
      this.start = this.start.next;
      nodeToRemove.next = null;

      if (this.length === 1) {
        this.end = null;
      }

      this.length -= 1;
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading-blue&quot;&gt;Further Reading 📖&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Queue_(abstract_data_type)&quot;&gt;Wikipedia: Queue&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Stacks_and_Queues#Queues&quot;&gt;Wikibooks: Queue&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;FIFO_(computing_and_electronics)&quot;&gt;Wikipedia: FIFO&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Can you implement a new method &lt;code&gt;peek&lt;&#x2F;code&gt;, that returns the start node, without removing it?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We will compare the Data Structures we&#x27;ve built so far.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t miss interesting stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Queue: Dequeue</title>
        <published>2020-01-03T00:00:00+00:00</published>
        <updated>2020-01-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-01-03/" type="text/html"/>
        <id>https://miku86.com/2020-01-03/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-enqueue&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned to enqueue a node to the end of the Queue.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to dequeue &#x2F; remove a new node from the start of the Queue.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-enqueue&quot;&gt;with the enqueue method&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Queue {
  constructor() {
    this.length = 0;
    this.start = null;
    this.end = null;
  }

  enqueue(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.start = newNode;
      this.end = newNode;
    } else {
      this.end.next = newNode;
      this.end = newNode;
    }

    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the Queue is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can&#x27;t remove a node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the Queue has one node:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;set the current start as the node to remove&lt;&#x2F;li&gt;
&lt;li&gt;set the node after the start as the new start&lt;&#x2F;li&gt;
&lt;li&gt;set the next node of the node to remove to null&lt;&#x2F;li&gt;
&lt;li&gt;set the end to null&lt;&#x2F;li&gt;
&lt;li&gt;decrease the queue&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the node to remove&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;set the current start as the node to remove&lt;&#x2F;li&gt;
&lt;li&gt;set the node after the start as the new start&lt;&#x2F;li&gt;
&lt;li&gt;set the next node of the node to remove to null&lt;&#x2F;li&gt;
&lt;li&gt;decrease the queue&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the node to remove&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we only have to change the end of the queue when we start with one node, because then there is no end left, because the queue will be empty&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current queue:
A (start) ==&amp;gt; B (end)

&amp;#x2F;&amp;#x2F; desired queue:
              B (start, end)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current queue:
A (start) ==&amp;gt; B (end)

&amp;#x2F;&amp;#x2F; set the node after the start as the new start
A         ==&amp;gt; B (start, end)

&amp;#x2F;&amp;#x2F; set the next node of the node to remove to null
A             B (start, end)

&amp;#x2F;&amp;#x2F; desired queue:
              B (start, end)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-memo&quot;&gt;Implementation 📝&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Queue {
  constructor() {
    this.length = 0;
    this.start = null;
    this.end = null;
  }

  enqueue(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.start = newNode;
      this.end = newNode;
    } else {
      this.end.next = newNode;
      this.end = newNode;
    }

    this.length += 1;
    return newNode;
  }

  dequeue() {
    if (!this.length) {
      return null;
    } else {
      &amp;#x2F;&amp;#x2F; set the current start as the node to remove
      const nodeToRemove = this.start;

      &amp;#x2F;&amp;#x2F; set the node after the start as the new start
      this.start = this.start.next;

      &amp;#x2F;&amp;#x2F; set the next node of the node to remove to null
      nodeToRemove.next = null;

      &amp;#x2F;&amp;#x2F; set the end to null, if the queue will be empty after removing
      if (this.length === 1) {
        this.end = null;
      }

      &amp;#x2F;&amp;#x2F; decrease the queue&amp;#x27;s length by 1
      this.length -= 1;

      &amp;#x2F;&amp;#x2F; return the node to remove
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the &lt;code&gt;dequeue&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newQueue = new Queue();
newQueue.enqueue(&amp;quot;new A&amp;quot;);
newQueue.enqueue(&amp;quot;new B&amp;quot;);

&amp;#x2F;&amp;#x2F; queue with 2 nodes
console.log(newQueue);
&amp;#x2F;&amp;#x2F; Queue {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   start: Node { value: &amp;#x27;new A&amp;#x27;, next: Node { value: &amp;#x27;new B&amp;#x27;, next: null } },
&amp;#x2F;&amp;#x2F;   end: Node { value: &amp;#x27;new B&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; remove the start, &amp;quot;new A&amp;quot;
console.log(newQueue.dequeue());
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new A&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; 1 node should be left, &amp;quot;new B&amp;quot;
console.log(newQueue);
&amp;#x2F;&amp;#x2F; Queue {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   start: Node { value: &amp;#x27;new B&amp;#x27;, next: null },
&amp;#x2F;&amp;#x2F;   end: Node { value: &amp;#x27;new B&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; remove the start, &amp;quot;new B&amp;quot;
console.log(newQueue.dequeue());
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new B&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; queue should be empty
console.log(newQueue);
&amp;#x2F;&amp;#x2F; Queue { length: 0, start: null, end: null }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We will do a small recap of our Queue.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t miss interesting stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;If we would implement the Queue by using an Array, how would we dequeue the start node?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Queue: Enqueue</title>
        <published>2020-01-02T00:00:00+00:00</published>
        <updated>2020-01-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2020-01-02/" type="text/html"/>
        <id>https://miku86.com/2020-01-02/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-intro&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned what a Queue is and set it up.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to enqueue &#x2F; add a new node to the end of the Queue.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code ▶️&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-queue-intro&quot;&gt;from the last part&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Queue {
  constructor() {
    this.length = 0;
    this.start = null;
    this.end = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts-thought-balloon&quot;&gt;Thoughts 💭&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the Queue is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as start and end&lt;&#x2F;li&gt;
&lt;li&gt;increase the queue&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the end&#x27;s next node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the new end&lt;&#x2F;li&gt;
&lt;li&gt;increase the queue&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current queue:
A (start) ==&amp;gt; B (end)

&amp;#x2F;&amp;#x2F; desired queue:
A (start) ==&amp;gt; B       ==&amp;gt; C (end)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current queue:
A (start) ==&amp;gt; B (end)

&amp;#x2F;&amp;#x2F; set the new node as the end&amp;#x27;s next node
A (start) ==&amp;gt; B (end) ==&amp;gt; C

&amp;#x2F;&amp;#x2F; set the new node as the new end
A (start) ==&amp;gt; B       ==&amp;gt; C (end)

&amp;#x2F;&amp;#x2F; desired queue:
A (start) ==&amp;gt; B       ==&amp;gt; C (end)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-memo&quot;&gt;Implementation 📝&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Queue {
  constructor() {
    this.length = 0;
    this.start = null;
    this.end = null;
  }

  enqueue(value) {
    &amp;#x2F;&amp;#x2F; create a new node
    const newNode = new Node(value);

    if (!this.length) {
      &amp;#x2F;&amp;#x2F; set the new node as start and end
      this.start = newNode;
      this.end = newNode;
    } else {
      &amp;#x2F;&amp;#x2F; set the new node as the end&amp;#x27;s next node
      this.end.next = newNode;
      &amp;#x2F;&amp;#x2F; set the new node as the new end
      this.end = newNode;
    }

    &amp;#x2F;&amp;#x2F; increase the queue&amp;#x27;s length by 1
    this.length += 1;
    &amp;#x2F;&amp;#x2F; return the new node
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the &lt;code&gt;enqueue&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newQueue = new Queue();

&amp;#x2F;&amp;#x2F; empty queue
console.log(newQueue);
&amp;#x2F;&amp;#x2F; Queue { length: 0, start: null, end: null }

console.log(newQueue.enqueue(&amp;quot;new A&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new A&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; queue with 1 node
console.log(newQueue);
&amp;#x2F;&amp;#x2F; Queue {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   start: Node { value: &amp;#x27;new A&amp;#x27;, next: null },
&amp;#x2F;&amp;#x2F;   end: Node { value: &amp;#x27;new A&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

console.log(newQueue.enqueue(&amp;quot;new B&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new B&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; queue with 2 nodes
console.log(newQueue);
&amp;#x2F;&amp;#x2F; Queue {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   start: Node { value: &amp;#x27;new A&amp;#x27;, next: Node { value: &amp;#x27;new B&amp;#x27;, next: null } },
&amp;#x2F;&amp;#x2F;   end: Node { value: &amp;#x27;new B&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;✅&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part-arrow-right&quot;&gt;Next Part ➡️&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method to &lt;code&gt;dequeue&lt;&#x2F;code&gt; the first node.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t miss interesting stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions-grey-question&quot;&gt;Questions ❔&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you see some similarities to the Singly Linked List or Doubly Linked List?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Queue: Intro</title>
        <published>2019-12-31T00:00:00+00:00</published>
        <updated>2019-12-31T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-31/" type="text/html"/>
        <id>https://miku86.com/2019-12-31/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;After we finished the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-intro&quot;&gt;small series about the Stack&lt;&#x2F;a&gt;, we start with the Queue.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;what-is-a-queue&quot;&gt;What is a Queue?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;uses the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Queue_(abstract_data_type)&quot;&gt;&amp;quot;First In, First Out&amp;quot;-Principle&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Examples: a queue of people in front of a store, a printer queue&lt;&#x2F;li&gt;
&lt;li&gt;there are multiple ways to implement a Queue: Array, Singly Linked List, Doubly Linked List&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;upload.wikimedia.org&#x2F;wikipedia&#x2F;commons&#x2F;thumb&#x2F;5&#x2F;52&#x2F;Data_Queue.svg&#x2F;320px-Data_Queue.svg.png&quot; alt=&quot;Queue&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;big-o-of-queue&quot;&gt;Big O of Queue&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Delete: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;We will use a Singly Linked List to build our Queue.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;A (start) ==&amp;gt; B (end)&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can enqueue (= add) to the end (e.g. a new person will be the last person in the queue)&lt;&#x2F;li&gt;
&lt;li&gt;we can dequeue (= remove) from the start (e.g. a person at the start gets served next)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;A&lt;&#x2F;code&gt; is the next node in line&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;A&lt;&#x2F;code&gt; has a pointer (&lt;code&gt;next&lt;&#x2F;code&gt;) to the next node (&lt;code&gt;B&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;B&lt;&#x2F;code&gt; is the last node we enqueued (= added) to the Queue&lt;&#x2F;li&gt;
&lt;li&gt;if we dequeue (= remove) &lt;code&gt;A&lt;&#x2F;code&gt;, the next node in line should be &lt;code&gt;B&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;setup&quot;&gt;Setup&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to build our Queue:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a Node with a value and a pointer to the next item in the Queue&lt;&#x2F;li&gt;
&lt;li&gt;a Queue with a length, a pointer to the start of the queue, a pointer to the end of the queue&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Node has a value (`value`) and a pointer to the next node (`next`)
class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

&amp;#x2F;&amp;#x2F; a Queue has a length, a start (`start`), an end (`end`)
class Queue {
  constructor() {
    this.length = 0;
    this.start = null;
    this.end = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;We set up our Queue. Now we need at least two methods within the Queue:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method that adds a new node to the end of the Queue: &lt;code&gt;enqueue&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;a method that removes a node from the start of the Queue: &lt;code&gt;dequeue&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our first method for the Queue.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t miss interesting stuff, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;We could also use an Array to build a Queue? How could we do this? Any pros or cons?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Stack: Recap</title>
        <published>2019-12-30T00:00:00+00:00</published>
        <updated>2019-12-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-30/" type="text/html"/>
        <id>https://miku86.com/2019-12-30/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-pop&quot;&gt;Last time&lt;&#x2F;a&gt;, we added the last method.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you learned something about the concept of a Stack and tried your best to implement it on your own.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;thoughts-about-the-stack&quot;&gt;Thoughts about the Stack&lt;&#x2F;h3&gt;
&lt;p&gt;We implemented the Stack using a &lt;a href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;2019-12-30&#x2F;js-ds-singly-linked-list-intro&quot;&gt;Singly Linked List&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The Stack data structure is a very important concept, because we use it all the time.&lt;&#x2F;p&gt;
&lt;p&gt;The fundamental difference to the Singly and Doubly Linked List is the fact, that we only add and remove a node to&#x2F;from the top of the Stack, so we use the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stack_(abstract_data_type)&quot;&gt;&amp;quot;Last In, First Out&amp;quot;-Principle&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Examples in real life are a stack of cards, a pile of dishes, a browser history.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Remove: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;final-implementation&quot;&gt;Final Implementation&lt;&#x2F;h2&gt;
&lt;p&gt;Our Stack has these methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;push&lt;&#x2F;code&gt;, to add a node to the top of the stack&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;pop&lt;&#x2F;code&gt;, to remove the top node from the stack&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Stack {
  constructor() {
    this.length = 0;
    this.last = null;
  }

  push(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.last = newNode;
    } else {
      newNode.next = this.last;
      this.last = newNode;
    }

    this.length += 1;
    return newNode;
  }

  pop() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.last;
      this.last = nodeToRemove.next;
      nodeToRemove.next = null;

      this.length -= 1;
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stack_(abstract_data_type)&quot;&gt;Wikipedia: Stack&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikibooks.org&#x2F;wiki&#x2F;Data_Structures&#x2F;Stacks_and_Queues#Stacks&quot;&gt;Wikibooks: Stack&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Call_stack&quot;&gt;Wikipedia: Call Stack&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stack_overflow&quot;&gt;Wikipedia: Stack Overflow&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Stack: Pop &#x2F; Remove the last node</title>
        <published>2019-12-20T00:00:00+00:00</published>
        <updated>2019-12-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-20/" type="text/html"/>
        <id>https://miku86.com/2019-12-20/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-push&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to add a new node to the Stack.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to pop &#x2F; remove the node on top of the Stack.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-push&quot;&gt;from the last part&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Stack {
  constructor() {
    this.length = 0;
    this.last = null;
  }

  push(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.last = newNode;
    } else {
      newNode.next = this.last;
      this.last = newNode;
    }

    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the Stack is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null, because we can&#x27;t remove a node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;set the current last node as the node to remove&lt;&#x2F;li&gt;
&lt;li&gt;set the last node&#x27;s next node as the new last node&lt;&#x2F;li&gt;
&lt;li&gt;remove the connection from the node to remove to its next node&lt;&#x2F;li&gt;
&lt;li&gt;decrease the stack&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current stack:
A        &amp;lt;== B (last)

&amp;#x2F;&amp;#x2F; desired stack:
A (last)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current stack:
A        &amp;lt;== B (last)

&amp;#x2F;&amp;#x2F; set the last node&amp;#x27;s next node as the new last node
A (last) &amp;lt;== B

&amp;#x2F;&amp;#x2F; remove the connection from the node to remove to its next node
A (last)

&amp;#x2F;&amp;#x2F; desired stack:
A (last)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;=&amp;gt; stack after last step equals the desired stack&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Stack {
  constructor() {
    this.length = 0;
    this.last = null;
  }

  push(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.last = newNode;
    } else {
      newNode.next = this.last;
      this.last = newNode;
    }

    this.length += 1;
    return newNode;
  }

  pop() {
    &amp;#x2F;&amp;#x2F; if the Stack is empty, return null, because we can&amp;#x27;t remove a node
    if (!this.length) {
      return null;
    } else {
      &amp;#x2F;&amp;#x2F; set the current last node as the node to remove
      const nodeToRemove = this.last;
      &amp;#x2F;&amp;#x2F; set the last node&amp;#x27;s next node as the new last node
      this.last = nodeToRemove.next;
      &amp;#x2F;&amp;#x2F; remove the connection from the node to remove to its next node
      nodeToRemove.next = null;

      &amp;#x2F;&amp;#x2F; decrease the stack&amp;#x27;s length by 1
      this.length -= 1;
      &amp;#x2F;&amp;#x2F; return the node
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the &lt;code&gt;pop&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newStack = new Stack();
newStack.push(&amp;quot;A&amp;quot;);
newStack.push(&amp;quot;B&amp;quot;);

&amp;#x2F;&amp;#x2F; should have two nodes, B at the top of the stack
console.log(newStack);
&amp;#x2F;&amp;#x2F; Stack {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   last: Node { value: &amp;#x27;B&amp;#x27;, next: Node { value: &amp;#x27;A&amp;#x27;, next: null } }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; remove the top one
console.log(newStack.pop());
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;B&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; should have one node, A at the top of the stack
console.log(newStack);
&amp;#x2F;&amp;#x2F; Stack { length: 1, last: Node { value: &amp;#x27;A&amp;#x27;, next: null } }

&amp;#x2F;&amp;#x2F; remove the top one
console.log(newStack.pop());
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;A&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; no node left :C
console.log(newStack);
&amp;#x2F;&amp;#x2F; Stack { length: 0, last: null }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will do a small recap of our Stack.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Stack: Push &#x2F; Add a new node</title>
        <published>2019-12-19T00:00:00+00:00</published>
        <updated>2019-12-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-19/" type="text/html"/>
        <id>https://miku86.com/2019-12-19/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-intro&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned what a Stack is and set it up.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to push &#x2F; add a new node on top of the Stack.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-stack-intro&quot;&gt;from the last part&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Stack {
  constructor() {
    this.length = 0;
    this.last = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the Stack is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the last node&lt;&#x2F;li&gt;
&lt;li&gt;increase the stack&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set the current last node as the new node&#x27;s next node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the new last node&lt;&#x2F;li&gt;
&lt;li&gt;increase the stack&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current stack:
A &amp;lt;== B (last)

&amp;#x2F;&amp;#x2F; desired stack:
A &amp;lt;== B        &amp;lt;== C (last)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current stack:
A &amp;lt;== B (last)

&amp;#x2F;&amp;#x2F; set the current last node as the new node&amp;#x27;s next node
A &amp;lt;== B (last) &amp;lt;== C

&amp;#x2F;&amp;#x2F; set the new node as the new last node
A &amp;lt;== B        &amp;lt;== C (last)

&amp;#x2F;&amp;#x2F; desired stack:
A &amp;lt;== B        &amp;lt;== C (last)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;=&amp;gt; stack after last step equals the desired stack&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class Stack {
  constructor() {
    this.length = 0;
    this.last = null;
  }

  push(value) {
    &amp;#x2F;&amp;#x2F; create a new node
    const newNode = new Node(value);

    if (!this.length) {
      &amp;#x2F;&amp;#x2F; stack is empty, therefore set the new node as the last node
      this.last = newNode;
    } else {
      &amp;#x2F;&amp;#x2F; set the current last node as the new node&amp;#x27;s next node
      newNode.next = this.last;
      &amp;#x2F;&amp;#x2F; set the new node as the new last node
      this.last = newNode;
    }

    &amp;#x2F;&amp;#x2F; increase the stack&amp;#x27;s length by 1
    this.length += 1;
    &amp;#x2F;&amp;#x2F; return the new node
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the &lt;code&gt;push&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newStack = new Stack();

&amp;#x2F;&amp;#x2F; should be empty
console.log(newStack);
&amp;#x2F;&amp;#x2F; Stack { length: 0, last: null }

&amp;#x2F;&amp;#x2F; one new node
console.log(newStack.push(&amp;quot;A&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;A&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; should have one node
console.log(newStack);
&amp;#x2F;&amp;#x2F; Stack { length: 1, last: Node { value: &amp;#x27;A&amp;#x27;, next: null } }

&amp;#x2F;&amp;#x2F; one new node
console.log(newStack.push(&amp;quot;B&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;B&amp;#x27;, next: Node { value: &amp;#x27;A&amp;#x27;, next: null } }

&amp;#x2F;&amp;#x2F; should have two nodes
console.log(newStack);
&amp;#x2F;&amp;#x2F; Stack {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   last: Node { value: &amp;#x27;B&amp;#x27;, next: Node { value: &amp;#x27;A&amp;#x27;, next: null } }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method to &lt;code&gt;pop&lt;&#x2F;code&gt; the last node.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Stack: Intro</title>
        <published>2019-12-18T00:00:00+00:00</published>
        <updated>2019-12-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-18/" type="text/html"/>
        <id>https://miku86.com/2019-12-18/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;After completing the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-intro&quot;&gt;series about the Doubly Linked List&lt;&#x2F;a&gt;,&lt;&#x2F;p&gt;
&lt;p&gt;we start with the Stack.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;what-is-a-stack&quot;&gt;What is a Stack?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;uses the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Stack_(abstract_data_type)&quot;&gt;&amp;quot;Last In, First Out&amp;quot;-Principle&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Examples: a stack of cards, a pile of dishes, a browser history&lt;&#x2F;li&gt;
&lt;li&gt;there are multiple ways to implement a Stack: Array, Singly Linked List, Doubly Linked List&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;upload.wikimedia.org&#x2F;wikipedia&#x2F;de&#x2F;thumb&#x2F;b&#x2F;b5&#x2F;Lifo.svg&#x2F;320px-Lifo.svg.png&quot; alt=&quot;Stack&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;big-o-of-stack&quot;&gt;Big O of Stack&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Delete: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;We will use a Singly Linked List to build our Stack.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;A &amp;lt;== B &amp;lt;== C (last)&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;C&lt;&#x2F;code&gt; is the last node we pushed (= added) on top of the Stack&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;C&lt;&#x2F;code&gt; has a pointer (&lt;code&gt;next&lt;&#x2F;code&gt;) to the next node (&lt;code&gt;B&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;if we pop (= remove) &lt;code&gt;C&lt;&#x2F;code&gt;, the next node on top of the Stack should be &lt;code&gt;B&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;setup&quot;&gt;Setup&lt;&#x2F;h2&gt;
&lt;p&gt;We need the following parts to build our Stack:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a Node with a value and a pointer to the next item in the Stack&lt;&#x2F;li&gt;
&lt;li&gt;a Stack with a length and a pointer to the last item&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Node has a value (`value`) and a pointer to the next node (`next`)
class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

&amp;#x2F;&amp;#x2F; a Stack has a length and a last item (`last`)
class Stack {
  constructor() {
    this.length = 0;
    this.last = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;We set up our Stack. Now we need at least two methods within the Stack:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a method that pushes a new node on top of the Stack: &lt;code&gt;push&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;a method that pops off the last node from the top of the Stack: &lt;code&gt;pop&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our first method for the Stack.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Can you think of some pros or cons of using the Singly Linked List instead of an Array or a Doubly Linked List?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Recap</title>
        <published>2019-12-17T00:00:00+00:00</published>
        <updated>2019-12-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-17/" type="text/html"/>
        <id>https://miku86.com/2019-12-17/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-remove&quot;&gt;Last time&lt;&#x2F;a&gt;, we added the last method.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you learned something about the concept of a Doubly Linked List and tried your best to implement it on your own.&lt;&#x2F;p&gt;
&lt;p&gt;Most of the time it deepens my knowledge if I go over it again. And again.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;thoughts-about-the-doubly-linked-list&quot;&gt;Thoughts about the Doubly Linked List&lt;&#x2F;h3&gt;
&lt;p&gt;This time we implemented the Linked List first, so that we have the knowledge to think about the Big O.&lt;&#x2F;p&gt;
&lt;p&gt;The fundamental difference to the Singly Linked List is the fact, that every node has a connection to its previous node and its next node, not only its next node.&lt;&#x2F;p&gt;
&lt;p&gt;That means if we want to do something near the end of the list, we can start from the tail of the Doubly Linked List and go to the previous nodes, instead of always starting from the head like in your Singly Linked List. If we can go backwards from the tail, we can half our average time to find a node.&lt;&#x2F;p&gt;
&lt;p&gt;On the other hand, a Doubly Linked List needs more memory, because every node has the additional &lt;code&gt;prev&lt;&#x2F;code&gt; property for the pointer to the previous node.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Remove: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;final-implementation-short-version&quot;&gt;Final Implementation (Short version)&lt;&#x2F;h2&gt;
&lt;p&gt;Our Doubly Linked List has these methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;get&lt;&#x2F;code&gt;, to get a specific node&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;set&lt;&#x2F;code&gt;, to update a specific node&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;push&lt;&#x2F;code&gt;, to add a node to the end&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;pop&lt;&#x2F;code&gt;, to remove a node from the end&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;unshift&lt;&#x2F;code&gt;, to add a node to the beginning&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;shift&lt;&#x2F;code&gt;, to remove a node from the beginning&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;insert&lt;&#x2F;code&gt;, to add a node at a specific index&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;remove&lt;&#x2F;code&gt;, to remove a node at a specific index&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  get(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      if (index &amp;lt; this.length &amp;#x2F; 2) {
        let counter = 0;
        currentNode = this.head;

        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        let counter = this.length - 1;

        currentNode = this.tail;

        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      return currentNode;
    }
  }

  set(index, value) {
    const currentNode = this.get(index);

    if (currentNode) {
      currentNode.value = value;
      return currentNode;
    } else {
      return null;
    }
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }

    this.length += 1;

    return newNode;
  }

  pop() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.tail;

      if (this.length === 1) {
        this.head = null;
        this.tail = null;
      } else {
        this.tail = this.tail.prev;
        this.tail.next = null;
        nodeToRemove.prev = null;
      }

      this.length -= 1;

      return nodeToRemove;
    }
  }

  unshift(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      newNode.next = this.head;
      this.head.prev = newNode;
      this.head = newNode;
    }

    this.length += 1;

    return newNode;
  }

  shift() {
    if (!this.length) {
      return null;
    }

    const nodeToRemove = this.head;

    if (this.length === 1) {
      this.head = null;
      this.tail = null;
    } else {
      this.head = nodeToRemove.next;
      this.head.prev = null;
      nodeToRemove.next = null;
    }

    this.length -= 1;

    return nodeToRemove;
  }

  insert(index, value) {
    if (index &amp;lt; 0 || index &amp;gt; this.length) {
      return null;
    } else if (index === 0) {
      return this.unshift(value);
    } else if (index === this.length) {
      return this.push(value);
    } else {
      const newNode = new Node(value);

      const newPrevNode = this.get(index - 1);
      const newNextNode = newPrevNode.next;

      newNode.prev = newPrevNode;
      newPrevNode.next = newNode;

      newNode.next = newNextNode;
      newNextNode.prev = newNode;

      this.length += 1;

      return newNode;
    }
  }

  remove(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else if (index === 0) {
      return this.shift();
    } else if (index === this.length - 1) {
      return this.pop();
    } else {
      const nodeToRemove = this.get(index);
      const prevNodeToRemove = nodeToRemove.prev;
      const nextNodeToRemove = nodeToRemove.next;

      nodeToRemove.prev = null;
      nodeToRemove.next = null;

      prevNodeToRemove.next = nextNodeToRemove;
      nextNodeToRemove.prev = prevNodeToRemove;

      this.length -= 1;

      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Remove a node at a specific index</title>
        <published>2019-12-16T00:00:00+00:00</published>
        <updated>2019-12-16T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-16/" type="text/html"/>
        <id>https://miku86.com/2019-12-16/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-insert&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to insert a new node at a specific index.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to remove a node at a specific index.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with code that has the &lt;code&gt;push&lt;&#x2F;code&gt;, &lt;code&gt;shift&lt;&#x2F;code&gt;, &lt;code&gt;pop&lt;&#x2F;code&gt; and &lt;code&gt;get&lt;&#x2F;code&gt; method,
because we can reuse them.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  shift() {
    if (!this.length) {
      return null;
    }

    const nodeToRemove = this.head;

    if (this.length === 1) {
      this.head = null;
      this.tail = null;
    } else {
      this.head = nodeToRemove.next;
      this.head.prev = null;
      nodeToRemove.next = null;
    }

    this.length -= 1;

    return nodeToRemove;
  }

  pop() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.tail;

      if (this.length === 1) {
        this.head = null;
        this.tail = null;
      } else {
        this.tail = this.tail.prev;
        this.tail.next = null;
        nodeToRemove.prev = null;
      }

      this.length -= 1;

      return nodeToRemove;
    }
  }

  get(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      if (index &amp;lt; this.length &amp;#x2F; 2) {
        let counter = 0;
        currentNode = this.head;

        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        let counter = this.length - 1;

        currentNode = this.tail;

        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the index is invalid (list is empty, index less than 0, greater than or equal to the list&#x27;s length):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If we want to remove the first node (index equals 0):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;use the &lt;code&gt;shift&lt;&#x2F;code&gt; method to add the data&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If we want to remove the last node (index equals length minus 1):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;use the &lt;code&gt;pop&lt;&#x2F;code&gt; method to add the data&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;store the node we want to remove, the node before it and the node after it&lt;&#x2F;li&gt;
&lt;li&gt;remove the connections from the node to remove to other nodes&lt;&#x2F;li&gt;
&lt;li&gt;update the connections from the node before the node to remove&lt;&#x2F;li&gt;
&lt;li&gt;update the connections from the node after the node to remove&lt;&#x2F;li&gt;
&lt;li&gt;decrease length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A &amp;lt;===&amp;gt; B &amp;lt;===&amp;gt; C
&amp;#x2F;&amp;#x2F; desired list:
A &amp;lt;===&amp;gt; C
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A &amp;lt;===&amp;gt; B &amp;lt;===&amp;gt; C

&amp;#x2F;&amp;#x2F; remove the connections from the node to remove to other nodes
A   ==&amp;gt; B &amp;lt;==   C

&amp;#x2F;&amp;#x2F; update the connections from the node before the node to remove
A   ==&amp;gt; C &amp;#x2F;&amp;#x2F; A.next to C instead of B
B &amp;lt;==   C &amp;#x2F;&amp;#x2F; C.prev to B, still

&amp;#x2F;&amp;#x2F; update the connections from the node after the node to remove
A &amp;lt;===&amp;gt; C &amp;#x2F;&amp;#x2F; finally, C.prev to A instead of B

&amp;#x2F;&amp;#x2F; desired list:
A &amp;lt;===&amp;gt; C
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;=&amp;gt; list after last step equals the desired list&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short&quot;&gt;Implementation (Short)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  shift() {
    if (!this.length) {
      return null;
    }

    const nodeToRemove = this.head;

    if (this.length === 1) {
      this.head = null;
      this.tail = null;
    } else {
      this.head = nodeToRemove.next;
      this.head.prev = null;
      nodeToRemove.next = null;
    }

    this.length -= 1;

    return nodeToRemove;
  }

  pop() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.tail;

      if (this.length === 1) {
        this.head = null;
        this.tail = null;
      } else {
        this.tail = this.tail.prev;
        this.tail.next = null;
        nodeToRemove.prev = null;
      }

      this.length -= 1;

      return nodeToRemove;
    }
  }

  get(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      if (index &amp;lt; this.length &amp;#x2F; 2) {
        let counter = 0;
        currentNode = this.head;

        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        let counter = this.length - 1;

        currentNode = this.tail;

        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      return currentNode;
    }
  }

  remove(index) {
    &amp;#x2F;&amp;#x2F; if the index is invalid, return null
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else if (index === 0) {
      &amp;#x2F;&amp;#x2F; if we want to remove the first node
      return this.shift();
    } else if (index === this.length - 1) {
      &amp;#x2F;&amp;#x2F; if we want to remove the last node
      return this.pop();
    } else {
      &amp;#x2F;&amp;#x2F; store the node we want to remove, the node before it and the node after it
      const nodeToRemove = this.get(index);
      const prevNodeToRemove = nodeToRemove.prev;
      const nextNodeToRemove = nodeToRemove.next;

      &amp;#x2F;&amp;#x2F; remove the connections from the node to remove to other nodes
      nodeToRemove.prev = null;
      nodeToRemove.next = null;

      &amp;#x2F;&amp;#x2F; update the connections from the node before the node to remove
      prevNodeToRemove.next = nextNodeToRemove;

      &amp;#x2F;&amp;#x2F; update the connections from the node after the node to remove
      nextNodeToRemove.prev = prevNodeToRemove;

      &amp;#x2F;&amp;#x2F; decrease length by 1
      this.length -= 1;

      &amp;#x2F;&amp;#x2F; return node
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;remove&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newDLL = new DoublyLinkedList();
newDLL.push(&amp;quot;new 0&amp;quot;);
newDLL.push(&amp;quot;new 1&amp;quot;);
newDLL.push(&amp;quot;new 2&amp;quot;);

&amp;#x2F;&amp;#x2F; should be a list with 3 nodes
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 3,
&amp;#x2F;&amp;#x2F;   head: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;new 0&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: null,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;new 1&amp;#x27;, prev: [Circular *1], next: [Node] }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;new 2&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: Node { value: &amp;#x27;new 1&amp;#x27;, prev: [Node], next: [Circular *2] },
&amp;#x2F;&amp;#x2F;     next: null
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; index invalid
console.log(newDLL.remove(-1));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; index invalid
console.log(newDLL.remove(5));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; should be new 0
console.log(newDLL.remove(0));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new 0&amp;#x27;, prev: null, next: null }

&amp;#x2F;&amp;#x2F; should be new 2 (we deleted new 0)
console.log(newDLL.remove(1));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new 2&amp;#x27;, prev: null, next: null }

&amp;#x2F;&amp;#x2F; should be a list with 1 node (we deleted 2 nodes from the initial 3 node list)
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;new 1&amp;#x27;, prev: null, next: null },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;new 1&amp;#x27;, prev: null, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will do a small recap of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Insert a new node at a specific index</title>
        <published>2019-12-13T00:00:00+00:00</published>
        <updated>2019-12-13T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-13/" type="text/html"/>
        <id>https://miku86.com/2019-12-13/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-set&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to update a specific node.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to insert a new node at a specific index.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with code that has the &lt;code&gt;push&lt;&#x2F;code&gt;, &lt;code&gt;unshift&lt;&#x2F;code&gt; and &lt;code&gt;get&lt;&#x2F;code&gt; method,
because we can reuse them to add data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  unshift(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      newNode.next = this.head;
      this.head.prev = newNode;
      this.head = newNode;
    }

    this.length += 1;
    return newNode;
  }

  get(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      if (index &amp;lt; this.length &amp;#x2F; 2) {
        let counter = 0;
        currentNode = this.head;

        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        let counter = this.length - 1;

        currentNode = this.tail;

        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the index is less than 0:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the index is greater than the list&#x27;s length:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the index equals 0:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;use the &lt;code&gt;unshift&lt;&#x2F;code&gt; method to add the data&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the index equals length:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;use the &lt;code&gt;push&lt;&#x2F;code&gt; method to add the data&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;find the node that is currently before the desired place and connect it to the new node&lt;&#x2F;li&gt;
&lt;li&gt;find the node that is currently at the desired place and connect it to the new node&lt;&#x2F;li&gt;
&lt;li&gt;increase the list&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A &amp;lt;===&amp;gt; B
&amp;#x2F;&amp;#x2F; desired list:
A &amp;lt;===&amp;gt; X &amp;lt;===&amp;gt; B
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A &amp;lt;===&amp;gt; B

&amp;#x2F;&amp;#x2F; find the node that is currently before the desired place and connect it to the new node
&amp;#x2F;&amp;#x2F; there is still the connection from B.prev to A
A &amp;lt;===&amp;gt; X
A &amp;lt;==   B

&amp;#x2F;&amp;#x2F; find the node that is currently at the desired place and connect it to the new node
A &amp;lt;===&amp;gt; X &amp;lt;===&amp;gt; B

&amp;#x2F;&amp;#x2F; desired list:
A &amp;lt;===&amp;gt; X &amp;lt;===&amp;gt; B
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;=&amp;gt; list after last step equals the desired list&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short&quot;&gt;Implementation (Short)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  unshift(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      newNode.next = this.head;
      this.head.prev = newNode;
      this.head = newNode;
    }

    this.length += 1;
    return newNode;
  }

  get(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      if (index &amp;lt; this.length &amp;#x2F; 2) {
        let counter = 0;
        currentNode = this.head;

        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        let counter = this.length - 1;

        currentNode = this.tail;

        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      return currentNode;
    }
  }

  insert(index, value) {
    &amp;#x2F;&amp;#x2F; if the index is less than 0 or greater than the list&amp;#x27;s length, return null
    if (index &amp;lt; 0 || index &amp;gt; this.length) {
      return null;
    } else if (index === 0) {
      &amp;#x2F;&amp;#x2F; if the index equals 0, use the `unshift` method
      return this.unshift(value);
    } else if (index === this.length) {
      &amp;#x2F;&amp;#x2F; if the index equals length, use the `push` method
      return this.push(value);
    } else {
      &amp;#x2F;&amp;#x2F; create new node
      const newNode = new Node(value);

      &amp;#x2F;&amp;#x2F; find the new previous node
      const newPrevNode = this.get(index - 1);
      &amp;#x2F;&amp;#x2F; find the new next node
      const newNextNode = newPrevNode.next;

      &amp;#x2F;&amp;#x2F; connect the new node to the new previous node
      newNode.prev = newPrevNode;
      newPrevNode.next = newNode;

      &amp;#x2F;&amp;#x2F; connect the new node to the new next node
      newNode.next = newNextNode;
      newNextNode.prev = newNode;

      &amp;#x2F;&amp;#x2F; increase the list&amp;#x27;s length by 1
      this.length += 1;

      &amp;#x2F;&amp;#x2F; return the new node
      return newNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;insert&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newDLL = new DoublyLinkedList();

&amp;#x2F;&amp;#x2F; index too low
console.log(newDLL.insert(-1, &amp;quot;too low&amp;quot;));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; should display the new node
console.log(newDLL.insert(0, &amp;quot;at 0&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;at 0&amp;#x27;, prev: null, next: null }

&amp;#x2F;&amp;#x2F; should display the new node
console.log(newDLL.insert(1, &amp;quot;at 1&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;at 1&amp;#x27;,
&amp;#x2F;&amp;#x2F;   prev: Node { value: &amp;#x27;at 0&amp;#x27;, prev: null, next: [Circular *1] },
&amp;#x2F;&amp;#x2F;   next: null
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; should insert the node between the other two nodes
console.log(newDLL.insert(1, &amp;quot;new at 1&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;new at 1&amp;#x27;,
&amp;#x2F;&amp;#x2F;   prev: Node { value: &amp;#x27;at 0&amp;#x27;, prev: null, next: [Circular *1] },
&amp;#x2F;&amp;#x2F;   next: Node { value: &amp;#x27;at 1&amp;#x27;, prev: [Circular *1], next: null }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; should show three nodes in the list: at 0 =&amp;gt; new at 1 =&amp;gt; at 1
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 3,
&amp;#x2F;&amp;#x2F;   head: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;at 0&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: null,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;new at 1&amp;#x27;, prev: [Circular *1], next: [Node] }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;at 1&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: Node { value: &amp;#x27;new at 1&amp;#x27;, prev: [Node], next: [Circular *2] },
&amp;#x2F;&amp;#x2F;     next: null
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method for the Doubly Linked List: &lt;code&gt;remove&lt;&#x2F;code&gt; a specific node.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Set &#x2F; Update a specific node</title>
        <published>2019-12-12T00:00:00+00:00</published>
        <updated>2019-12-12T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-12/" type="text/html"/>
        <id>https://miku86.com/2019-12-12/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-get&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to get a specific node by its index from our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to set &#x2F; update a specific node.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-get&quot;&gt;code that has the &lt;code&gt;push&lt;&#x2F;code&gt; and the &lt;code&gt;get&lt;&#x2F;code&gt; method&lt;&#x2F;a&gt;.
To update a node, we first have to add data.
To find a node, we can use our &lt;code&gt;get&lt;&#x2F;code&gt; method.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  get(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      if (index &amp;lt; this.length &amp;#x2F; 2) {
        let counter = 0;
        currentNode = this.head;

        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        let counter = this.length - 1;
        currentNode = this.tail;

        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;Because we can use our created &lt;code&gt;get&lt;&#x2F;code&gt; method, this is really simple.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;find the desired node&lt;&#x2F;li&gt;
&lt;li&gt;if we can find the node: update its value and return the node&lt;&#x2F;li&gt;
&lt;li&gt;if we can&#x27;t find the node: return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short&quot;&gt;Implementation (Short)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  get(index) {
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      if (index &amp;lt; this.length &amp;#x2F; 2) {
        let counter = 0;
        currentNode = this.head;

        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        let counter = this.length - 1;
        currentNode = this.tail;

        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      return currentNode;
    }
  }

  set(index, value) {
    &amp;#x2F;&amp;#x2F; find the desired node
    const currentNode = this.get(index);

    &amp;#x2F;&amp;#x2F; if we can find the node
    if (currentNode) {
      &amp;#x2F;&amp;#x2F; update its value
      currentNode.value = value;
      &amp;#x2F;&amp;#x2F; return the updated node
      return currentNode;
    } else {
      &amp;#x2F;&amp;#x2F; if we can&amp;#x27;t find the node: return null
      return null;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;set&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newDLL = new DoublyLinkedList();
newDLL.push(&amp;quot;A&amp;quot;);

&amp;#x2F;&amp;#x2F; should have one node
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;A&amp;#x27;, prev: null, next: null },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;A&amp;#x27;, prev: null, next: null }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; index too low
console.log(newDLL.set(-1, &amp;quot;too low&amp;quot;));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; should display the updated node
console.log(newDLL.set(0, &amp;quot;updated A&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;updated A&amp;#x27;, prev: null, next: null }

&amp;#x2F;&amp;#x2F; index too high
console.log(newDLL.set(1, &amp;quot;too high&amp;quot;));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; should have one node with the update value
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;updated A&amp;#x27;, prev: null, next: null },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;updated A&amp;#x27;, prev: null, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method for the Doubly Linked List: &lt;code&gt;insert&lt;&#x2F;code&gt; &#x2F; add a new node at a specific index.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Get a specific node by its index</title>
        <published>2019-12-11T00:00:00+00:00</published>
        <updated>2019-12-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-11/" type="text/html"/>
        <id>https://miku86.com/2019-12-11/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-shift&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to shift &#x2F; remove data from the beginning of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to get a specific node by its index.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-push&quot;&gt;code that has the &lt;code&gt;push&lt;&#x2F;code&gt; method&lt;&#x2F;a&gt;, because to remove data, we first have to add data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the list is empty, if the index is less than 0, or if the index is greater than or equal to the list length:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the desired node is in the bottom half of the list:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;add counter&lt;&#x2F;li&gt;
&lt;li&gt;start from the head&lt;&#x2F;li&gt;
&lt;li&gt;go to the next node until we found our desired node&lt;&#x2F;li&gt;
&lt;li&gt;return node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the desired node is in the top half of the list:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;add counter&lt;&#x2F;li&gt;
&lt;li&gt;start from the tail&lt;&#x2F;li&gt;
&lt;li&gt;go to the previous node until we found our desired node&lt;&#x2F;li&gt;
&lt;li&gt;return node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example:&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A (head) &amp;lt;===&amp;gt; B &amp;lt;===&amp;gt; C (tail)

&amp;#x2F;&amp;#x2F; desired node:
get(0); &amp;#x2F;&amp;#x2F; A (starting from head)
get(1); &amp;#x2F;&amp;#x2F; B (starting node doesn&amp;#x27;t matter, equal distance from head or tail)
get(2); &amp;#x2F;&amp;#x2F; C (starting from tail)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short&quot;&gt;Implementation (Short)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  get(index) {
    &amp;#x2F;&amp;#x2F; if list is empty, if index is less than 0, or if index is greater than or equal to the list length, return null
    if (!this.length || index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode;

      &amp;#x2F;&amp;#x2F; if the desired node is in the bottom half of the list
      if (index &amp;lt; this.length &amp;#x2F; 2) {
        &amp;#x2F;&amp;#x2F; add counter, starting from 0 and counting upwards in the loop
        let counter = 0;

        &amp;#x2F;&amp;#x2F; start from the head
        currentNode = this.head;

        &amp;#x2F;&amp;#x2F; go to the next node until we found our desired node
        while (counter &amp;lt; index) {
          currentNode = currentNode.next;
          counter += 1;
        }
      } else {
        &amp;#x2F;&amp;#x2F; add counter, starting from the top and counting downwards in the loop
        let counter = this.length - 1;

        &amp;#x2F;&amp;#x2F; start from the tail
        currentNode = this.tail;

        &amp;#x2F;&amp;#x2F; go to the previous node until we found our desired node
        while (counter &amp;gt; index) {
          currentNode = currentNode.prev;
          counter -= 1;
        }
      }

      &amp;#x2F;&amp;#x2F; return node
      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;get&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newDLL = new DoublyLinkedList();
newDLL.push(&amp;quot;A&amp;quot;);
newDLL.push(&amp;quot;B&amp;quot;);
newDLL.push(&amp;quot;C&amp;quot;);

&amp;#x2F;&amp;#x2F; nothing to see
console.log(newDLL.get(-1));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; should be A
console.log(newDLL.get(0));
&amp;#x2F;&amp;#x2F; &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;   prev: null,
&amp;#x2F;&amp;#x2F;   next: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;B&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: [Circular *1],
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;C&amp;#x27;, prev: [Circular *2], next: null }
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; should be B
console.log(newDLL.get(1));
&amp;#x2F;&amp;#x2F; &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;B&amp;#x27;,
&amp;#x2F;&amp;#x2F;   prev: Node { value: &amp;#x27;A&amp;#x27;, prev: null, next: [Circular *1] },
&amp;#x2F;&amp;#x2F;   next: Node { value: &amp;#x27;C&amp;#x27;, prev: [Circular *1], next: null }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; should be C
console.log(newDLL.get(2));
&amp;#x2F;&amp;#x2F; &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;C&amp;#x27;,
&amp;#x2F;&amp;#x2F;   prev: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;B&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: Node { value: &amp;#x27;A&amp;#x27;, prev: null, next: [Circular *1] },
&amp;#x2F;&amp;#x2F;     next: [Circular *2]
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   next: null
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F;  nothing to see
console.log(newDLL.get(3));
&amp;#x2F;&amp;#x2F; null
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method for the Doubly Linked List: &lt;code&gt;set&lt;&#x2F;code&gt; &#x2F; update a specific node.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Shift &#x2F; Remove data from the beginning</title>
        <published>2019-12-10T00:00:00+00:00</published>
        <updated>2019-12-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-10/" type="text/html"/>
        <id>https://miku86.com/2019-12-10/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-unshift&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to unshift &#x2F; add data to the beginning of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to shift &#x2F; remove data from the beginning of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-push&quot;&gt;code that has the &lt;code&gt;push&lt;&#x2F;code&gt; method&lt;&#x2F;a&gt;, because to remove data, we first have to add data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the list is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can&#x27;t remove data from an empty list, therefore we return &lt;code&gt;null&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the list has 1 element:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;set head as nodeToRemove&lt;&#x2F;li&gt;
&lt;li&gt;after removing the only element, the list will be empty, so &lt;code&gt;head&lt;&#x2F;code&gt; and &lt;code&gt;tail&lt;&#x2F;code&gt; should be &lt;code&gt;null&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;decrease length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return nodeToRemove&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;set head as nodeToRemove&lt;&#x2F;li&gt;
&lt;li&gt;the node after the nodeToRemove should become the new head&lt;&#x2F;li&gt;
&lt;li&gt;remove both connections from the new head to the old head (our nodeToRemove)&lt;&#x2F;li&gt;
&lt;li&gt;decrease length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return nodeToRemove&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can see some duplication (set head as nodeToRemove, decrease length, return nodeToRemove)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;example&quot;&gt;Example:&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A (head) &amp;lt;===&amp;gt; B (tail)

&amp;#x2F;&amp;#x2F; desired list:
               B (head &amp;amp; tail)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A (head) &amp;lt;===&amp;gt; B (tail)

&amp;#x2F;&amp;#x2F; the node after the nodeToRemove should become the new head
A        &amp;lt;===&amp;gt; B (head &amp;amp; tail)

&amp;#x2F;&amp;#x2F; remove both connections from the new head to the old head (our nodeToRemove)
A              B (head &amp;amp; tail)

&amp;#x2F;&amp;#x2F; desired list:
               B (head &amp;amp; tail)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;=&amp;gt; list after last step equals the desired list&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short&quot;&gt;Implementation (Short)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }
    this.length += 1;
    return newNode;
  }

  shift() {
    &amp;#x2F;&amp;#x2F; we can&amp;#x27;t remove data from an empty list
    if (!this.length) {
      return null;
    }

    &amp;#x2F;&amp;#x2F; set head as nodeToRemove
    const nodeToRemove = this.head;

    if (this.length === 1) {
      &amp;#x2F;&amp;#x2F; after removing the only element, the list will be empty, so `head` and `tail` should be `null`
      this.head = null;
      this.tail = null;
    } else {
      &amp;#x2F;&amp;#x2F; the node after the nodeToRemove should become the new head
      this.head = nodeToRemove.next;

      &amp;#x2F;&amp;#x2F; remove both connections from the new head to the old head (= nodeToRemove)
      this.head.prev = null;
      nodeToRemove.next = null;
    }

    &amp;#x2F;&amp;#x2F; decrease length by 1
    this.length -= 1;

    &amp;#x2F;&amp;#x2F; return nodeToRemove
    return nodeToRemove;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;shift&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newDLL = new DoublyLinkedList();
newDLL.push(&amp;quot;A&amp;quot;);
newDLL.push(&amp;quot;B&amp;quot;);

&amp;#x2F;&amp;#x2F; should show two nodes
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: null,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;B&amp;#x27;, prev: [Circular *1], next: null }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;B&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;       value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;       prev: null,
&amp;#x2F;&amp;#x2F;       next: [Circular *2]
&amp;#x2F;&amp;#x2F;     },
&amp;#x2F;&amp;#x2F;     next: null
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; should show node with value A
console.log(newDLL.shift());
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;A&amp;#x27;, prev: null, next: null }

&amp;#x2F;&amp;#x2F; should show one node left, B
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;B&amp;#x27;, prev: null, next: null },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;B&amp;#x27;, prev: null, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method for the Doubly Linked List: &lt;code&gt;get&lt;&#x2F;code&gt; &#x2F; get a specific node by its index.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Unshift &#x2F; Add data to the beginning</title>
        <published>2019-12-09T00:00:00+00:00</published>
        <updated>2019-12-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-09/" type="text/html"/>
        <id>https://miku86.com/2019-12-09/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-pop&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to pop &#x2F; remove data from end of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to unshift &#x2F; add data to the beginning of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-intro&quot;&gt;setup code&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the list is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the new head and tail&lt;&#x2F;li&gt;
&lt;li&gt;increase length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set new node&#x27;s next to current head&lt;&#x2F;li&gt;
&lt;li&gt;set the current head&#x27;s prev to new node&lt;&#x2F;li&gt;
&lt;li&gt;set list&#x27;s head to new node&lt;&#x2F;li&gt;
&lt;li&gt;increase length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can see some duplication (create node, increase length, return node)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example: three nodes&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
               A (head) &amp;lt;===&amp;gt; B (tail)

&amp;#x2F;&amp;#x2F; desired list:
0 (head) &amp;lt;===&amp;gt; A        &amp;lt;===&amp;gt; B (tail)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
               A (head) &amp;lt;===&amp;gt; B (tail)

&amp;#x2F;&amp;#x2F; set new node&amp;#x27;s next to current head
0          ==&amp;gt; A (head) &amp;lt;===&amp;gt; B (tail)

&amp;#x2F;&amp;#x2F; set the current head&amp;#x27;s prev to new node
0        &amp;lt;===&amp;gt; A (head) &amp;lt;===&amp;gt; B (tail)

&amp;#x2F;&amp;#x2F; set list&amp;#x27;s head to new node
0 (head) &amp;lt;===&amp;gt; A        &amp;lt;===&amp;gt; B (tail)

&amp;#x2F;&amp;#x2F; desired list:
0 (head) &amp;lt;===&amp;gt; A        &amp;lt;===&amp;gt; B (tail)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;=&amp;gt; list after last step equals the desired list&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short&quot;&gt;Implementation (Short)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  unshift(value) {
    &amp;#x2F;&amp;#x2F; create new node
    const newNode = new Node(value);

    &amp;#x2F;&amp;#x2F; if list is empty: set head and tail to new node
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      &amp;#x2F;&amp;#x2F; set new node&amp;#x27;s next to current head
      newNode.next = this.head;

      &amp;#x2F;&amp;#x2F; set the current head&amp;#x27;s prev to new node
      this.head.prev = newNode;

      &amp;#x2F;&amp;#x2F; set list&amp;#x27;s head to new node
      this.head = newNode;
    }

    &amp;#x2F;&amp;#x2F; increase length by 1
    this.length += 1;

    &amp;#x2F;&amp;#x2F; return new node
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;unshift&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newDLL = new DoublyLinkedList();
newDLL.push(&amp;quot;A&amp;quot;);

&amp;#x2F;&amp;#x2F; should be a list with one node
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;A&amp;#x27;, prev: null, next: null },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;A&amp;#x27;, prev: null, next: null }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; should be the new node
console.log(newDLL.unshift(&amp;quot;0&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;0&amp;#x27;,
&amp;#x2F;&amp;#x2F;   prev: null,
&amp;#x2F;&amp;#x2F;   next: Node { value: &amp;#x27;A&amp;#x27;, prev: [Circular *1], next: null }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; should be a list with two nodes, node with value 0 at the beginning
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;0&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: null,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;A&amp;#x27;, prev: [Circular *1], next: null }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;       value: &amp;#x27;0&amp;#x27;,
&amp;#x2F;&amp;#x2F;       prev: null,
&amp;#x2F;&amp;#x2F;       next: [Circular *2]
&amp;#x2F;&amp;#x2F;     },
&amp;#x2F;&amp;#x2F;     next: null
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method for the Doubly Linked List: &lt;code&gt;shift&lt;&#x2F;code&gt; &#x2F; remove data from the beginning.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Pop &#x2F; Remove data from the end</title>
        <published>2019-12-06T00:00:00+00:00</published>
        <updated>2019-12-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-06/" type="text/html"/>
        <id>https://miku86.com/2019-12-06/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-push&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to add data to the end of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to pop data from the end of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with code that has the &lt;code&gt;push&lt;&#x2F;code&gt; method, because to remove data, we first have to add data.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }

    this.length += 1;

    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the list is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If the list has one node:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;save current tail (to return it later)&lt;&#x2F;li&gt;
&lt;li&gt;set the head and the tail to null&lt;&#x2F;li&gt;
&lt;li&gt;decrease length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the old tail&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;save current tail (to return it later)&lt;&#x2F;li&gt;
&lt;li&gt;set the node before the current tail as the new tail&lt;&#x2F;li&gt;
&lt;li&gt;remove the connection from the new tail to the old tail&lt;&#x2F;li&gt;
&lt;li&gt;remove the connection from the old tail to the new tail&lt;&#x2F;li&gt;
&lt;li&gt;decrease length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return old tail&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can see some duplication (save current tail, decrease length, return node)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example: three nodes&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A &amp;lt;===&amp;gt; B        &amp;lt;===&amp;gt; C (tail)
&amp;#x2F;&amp;#x2F; desired list:
A &amp;lt;===&amp;gt; B (tail)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; current list:
A &amp;lt;===&amp;gt; B        &amp;lt;===&amp;gt; C (tail)
&amp;#x2F;&amp;#x2F; set the node before the current tail as the new tail:
A &amp;lt;===&amp;gt; B (tail) &amp;lt;===&amp;gt; C
&amp;#x2F;&amp;#x2F; remove the connection from the new tail to the old tail:
A &amp;lt;===&amp;gt; B (tail) &amp;lt;== C
&amp;#x2F;&amp;#x2F; remove the connection from the old tail to the new tail:
A &amp;lt;===&amp;gt; B (tail)     C (not connected to list anymore)
&amp;#x2F;&amp;#x2F; desired list:
A &amp;lt;===&amp;gt; B (tail)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;=&amp;gt; list after last step equals the desired list&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short&quot;&gt;Implementation (Short)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      this.tail.next = newNode;
      newNode.prev = this.tail;
      this.tail = newNode;
    }

    this.length += 1;

    return newNode;
  }

  pop() {
    &amp;#x2F;&amp;#x2F; if empty: return null
    if (!this.length) {
      return null;
    } else {
      &amp;#x2F;&amp;#x2F; save current tail (to return it later)
      const nodeToRemove = this.tail;

      if (this.length === 1) {
        &amp;#x2F;&amp;#x2F; after removing the only node, there will be no head and tail
        this.head = null;
        this.tail = null;
      } else {
        &amp;#x2F;&amp;#x2F; set the node before the current tail as the new tail
        this.tail = this.tail.prev;
        &amp;#x2F;&amp;#x2F; remove the connection from the new tail to the old tail
        this.tail.next = null;
        &amp;#x2F;&amp;#x2F; remove the connection from the old tail to the new tail
        nodeToRemove.prev = null;
      }

      &amp;#x2F;&amp;#x2F; decrease length by 1
      this.length -= 1;

      &amp;#x2F;&amp;#x2F; return old tail
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;pop&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create new list and add three nodes
const newDLL = new DoublyLinkedList();
newDLL.push(&amp;quot;A&amp;quot;);
newDLL.push(&amp;quot;B&amp;quot;);
newDLL.push(&amp;quot;C&amp;quot;);
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 3,
&amp;#x2F;&amp;#x2F;   head: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: null,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;B&amp;#x27;, prev: [Circular *1], next: [Node] }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;C&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: Node { value: &amp;#x27;B&amp;#x27;, prev: [Node], next: [Circular *2] },
&amp;#x2F;&amp;#x2F;     next: null
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }

console.log(newDLL.pop());
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;C&amp;#x27;, prev: null, next: null }

console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: null,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;B&amp;#x27;, prev: [Circular *1], next: null }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;B&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;       value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;       prev: null,
&amp;#x2F;&amp;#x2F;       next: [Circular *2]
&amp;#x2F;&amp;#x2F;     },
&amp;#x2F;&amp;#x2F;     next: null
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method for the Doubly Linked List: &lt;code&gt;unshift&lt;&#x2F;code&gt; &#x2F; add data to the beginning.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Push &#x2F; Add data to the end</title>
        <published>2019-12-05T00:00:00+00:00</published>
        <updated>2019-12-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-05/" type="text/html"/>
        <id>https://miku86.com/2019-12-05/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-intro&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to setup our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we&#x27;ll learn how to push a new node to the end of our Doubly Linked List.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;starter-code&quot;&gt;Starter Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-doubly-linked-list-intro&quot;&gt;setup code from the last post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the list is empty:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;the new node should become the head and the tail&lt;&#x2F;li&gt;
&lt;li&gt;increase the List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;the current tail should point forward (= next) to the new node&lt;&#x2F;li&gt;
&lt;li&gt;the new node should point back (= prev) to the current tail&lt;&#x2F;li&gt;
&lt;li&gt;the new node should become the new tail&lt;&#x2F;li&gt;
&lt;li&gt;increase the List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example: empty list&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;current List: empty (no head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;desired List: A (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example 2: list with 1 node&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;current List: A (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;desired List: A (head) &amp;lt;===&amp;gt; B (tail)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;current List: A (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;desired List: A (head) &amp;lt;===&amp;gt; B (tail)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;the current tail should point forward (= next) to the new node&lt;&#x2F;code&gt;: A (head &amp;amp; tail) =&amp;gt; B&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;the new node should point back (= prev) to the current tail&lt;&#x2F;code&gt;: A (head &amp;amp; tail) &amp;lt;===&amp;gt; B&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;the new node should become the new tail&lt;&#x2F;code&gt;: A (head) &amp;lt;===&amp;gt; B (tail)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;=&amp;gt; list after last step equals the desired list&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    &amp;#x2F;&amp;#x2F; create a new node
    const newNode = new Node(value);

    &amp;#x2F;&amp;#x2F; if the list is empty,the new node should become the head and the tail
    if (!this.length) {
      this.head = newNode;
      this.tail = newNode;
    } else {
      &amp;#x2F;&amp;#x2F; the current tail should point forward (= next) to the new node
      this.tail.next = newNode;

      &amp;#x2F;&amp;#x2F; the new node should point back (= prev) to the current tail
      newNode.prev = this.tail;

      &amp;#x2F;&amp;#x2F; the new node should become the new tail
      this.tail = newNode;
    }

    &amp;#x2F;&amp;#x2F; increase length by 1
    this.length += 1;

    &amp;#x2F;&amp;#x2F; return new node
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Doubly Linked List&#x27;s &lt;code&gt;push&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; empty list
const newDLL = new DoublyLinkedList();
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList { length: 0, head: null, tail: null }

&amp;#x2F;&amp;#x2F; push first new node
console.log(newDLL.push(&amp;quot;new node 1&amp;quot;));
&amp;#x2F;&amp;#x2F;  Node { value: &amp;#x27;new node 1&amp;#x27;, prev: null, next: null }

console.log(newDLL);
&amp;#x2F;&amp;#x2F;  DoublyLinkedList {
&amp;#x2F;&amp;#x2F;    length: 1,
&amp;#x2F;&amp;#x2F;    head: Node { value: &amp;#x27;new node 1&amp;#x27;, prev: null, next: null },
&amp;#x2F;&amp;#x2F;    tail: Node { value: &amp;#x27;new node 1&amp;#x27;, prev: null, next: null }
&amp;#x2F;&amp;#x2F;  }

&amp;#x2F;&amp;#x2F; push second new node
console.log(newDLL.push(&amp;quot;new node 2&amp;quot;));
&amp;#x2F;&amp;#x2F; &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;new node 2&amp;#x27;,
&amp;#x2F;&amp;#x2F;   prev: Node { value: &amp;#x27;new node 1&amp;#x27;, prev: null, next: [Circular *1] },
&amp;#x2F;&amp;#x2F;   next: null
&amp;#x2F;&amp;#x2F; }

console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;new node 1&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: null,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;new node 2&amp;#x27;, prev: [Circular *1], next: null }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: &amp;lt;ref *2&amp;gt; Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;new node 2&amp;#x27;,
&amp;#x2F;&amp;#x2F;     prev: &amp;lt;ref *1&amp;gt; Node {
&amp;#x2F;&amp;#x2F;       value: &amp;#x27;new node 1&amp;#x27;,
&amp;#x2F;&amp;#x2F;       prev: null,
&amp;#x2F;&amp;#x2F;       next: [Circular *2]
&amp;#x2F;&amp;#x2F;     },
&amp;#x2F;&amp;#x2F;     next: null
&amp;#x2F;&amp;#x2F;   }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our next method for the Doubly Linked List: &lt;code&gt;pop&lt;&#x2F;code&gt; &#x2F; remove a node from the end.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;tasks&quot;&gt;Tasks&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you spot some new stuff in the results?&lt;&#x2F;li&gt;
&lt;li&gt;What do they mean?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Doubly Linked List: Intro and Setup</title>
        <published>2019-12-04T00:00:00+00:00</published>
        <updated>2019-12-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-04/" type="text/html"/>
        <id>https://miku86.com/2019-12-04/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;After completing the &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-intro&quot;&gt;series about the Singly Linked List&lt;&#x2F;a&gt;,&lt;&#x2F;p&gt;
&lt;p&gt;we start with the Doubly Linked List.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-a-doubly-linked-list&quot;&gt;What is a Doubly Linked List?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;the Doubly Linked List consists of nodes&lt;&#x2F;li&gt;
&lt;li&gt;each node has a value&lt;&#x2F;li&gt;
&lt;li&gt;each node has a pointer to the previous node (or null at the beginning of the list)&lt;&#x2F;li&gt;
&lt;li&gt;each node has a pointer to the next node (or null at the end of the list)&lt;&#x2F;li&gt;
&lt;li&gt;the List has a head (= beginning)&lt;&#x2F;li&gt;
&lt;li&gt;the List has a tail (= end)&lt;&#x2F;li&gt;
&lt;li&gt;the List has a length (= how many nodes are in the List)&lt;&#x2F;li&gt;
&lt;li&gt;the List has no index like an Array&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;doubly&amp;quot; means every node has two connections (one to the previous node and one to the next node)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;example&quot;&gt;Example&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;code&gt;A &amp;lt;===&amp;gt; B &amp;lt;===&amp;gt; C&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;A: prev: null&lt;&#x2F;li&gt;
&lt;li&gt;A: next: B&lt;&#x2F;li&gt;
&lt;li&gt;B: prev: A&lt;&#x2F;li&gt;
&lt;li&gt;B: next: C&lt;&#x2F;li&gt;
&lt;li&gt;C: prev: B&lt;&#x2F;li&gt;
&lt;li&gt;C: next: null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;big-o-of-doubly-linked-list&quot;&gt;Big O of Doubly Linked List&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Delete: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;setup&quot;&gt;Setup&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a Node has a value, a pointer to the previous node (= prev), a pointer to the next node (= next)
class Node {
  constructor(value) {
    this.value = value;
    this.prev = null;
    this.next = null;
  }
}

&amp;#x2F;&amp;#x2F; a Doubly Linked List has a length, a beginning (= head), an end (= tail)
class DoublyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newNode = new Node(1);
console.log(newNode);
&amp;#x2F;&amp;#x2F; Node { value: 1, prev: null, next: null }

const newDLL = new DoublyLinkedList();
console.log(newDLL);
&amp;#x2F;&amp;#x2F; DoublyLinkedList { length: 0, head: null, tail: null }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will implement our first method to the list.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to get notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;newsletter&quot;&gt;subscribe&lt;&#x2F;a&gt;!&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What do you think is a suitable use case for a Doubly Linked List?&lt;&#x2F;li&gt;
&lt;li&gt;Can you find some advantages against a Singly Linked List?&lt;&#x2F;li&gt;
&lt;li&gt;Can you find some disadvantages against a Singly Linked List?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Recap</title>
        <published>2019-12-02T00:00:00+00:00</published>
        <updated>2019-12-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-02/" type="text/html"/>
        <id>https://miku86.com/2019-12-02/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-remove&quot;&gt;Last time&lt;&#x2F;a&gt;, we added the last method.&lt;&#x2F;p&gt;
&lt;p&gt;I hope you learned something about the concept of a Singly Linked List and tried your best to implement it on your own.&lt;&#x2F;p&gt;
&lt;p&gt;Most of the time it deepens my knowledge if I go over it again. And again.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;final-implementation-short-version&quot;&gt;Final Implementation (Short version)&lt;&#x2F;h2&gt;
&lt;p&gt;Our Singly Linked List has these methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;get a specific node&lt;&#x2F;li&gt;
&lt;li&gt;update a specific node&lt;&#x2F;li&gt;
&lt;li&gt;add a node to the end&lt;&#x2F;li&gt;
&lt;li&gt;remove a node from the end&lt;&#x2F;li&gt;
&lt;li&gt;add a node to the beginning&lt;&#x2F;li&gt;
&lt;li&gt;remove a node from the beginning&lt;&#x2F;li&gt;
&lt;li&gt;add a node at a specific index&lt;&#x2F;li&gt;
&lt;li&gt;remove a node at a specific index&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  &amp;#x2F;&amp;#x2F; get a specific node
  get(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode = this.head;
      let count = 0;

      while (count &amp;lt; index) {
        currentNode = currentNode.next;
        count += 1;
      }

      return currentNode;
    }
  }

  &amp;#x2F;&amp;#x2F; update a specific node
  set(index, value) {
    const currentNode = this.get(index);

    if (currentNode) {
      currentNode.value = value;
      return currentNode;
    } else {
      return null;
    }
  }

  &amp;#x2F;&amp;#x2F; add to the end
  push(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.head = newNode;
    } else {
      this.tail.next = newNode;
    }

    this.tail = newNode;
    this.length += 1;

    return newNode;
  }

  &amp;#x2F;&amp;#x2F; remove from the end
  pop() {
    if (!this.length) {
      return null;
    } else {
      let nodeToRemove = this.head;
      let secondToLastNode = this.head;

      while (nodeToRemove.next) {
        secondToLastNode = nodeToRemove;
        nodeToRemove = nodeToRemove.next;
      }

      secondToLastNode.next = null;
      this.tail = secondToLastNode;
      this.length -= 1;

      if (!this.length) {
        this.head = null;
        this.tail = null;
      }

      return nodeToRemove;
    }
  }

  &amp;#x2F;&amp;#x2F; add to the beginning
  unshift(value) {
    const newNode = new Node(value);

    if (!this.length) {
      this.tail = newNode;
    } else {
      newNode.next = this.head;
    }

    this.head = newNode;
    this.length += 1;

    return newNode;
  }

  &amp;#x2F;&amp;#x2F; remove from the beginning
  shift() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.head;
      this.head = this.head.next;
      this.length -= 1;

      if (!this.length) {
        this.tail = null;
      }

      return nodeToRemove;
    }
  }

  &amp;#x2F;&amp;#x2F; add at a specific index
  insert(index, value) {
    if (index &amp;lt; 0 || index &amp;gt; this.length) {
      return null;
    } else if (index === 0) {
      return this.unshift(value);
    } else if (index === this.length) {
      return this.push(value);
    } else {
      const preNewNode = this.get(index - 1);
      const newNode = new Node(value);
      newNode.next = preNewNode.next;
      preNewNode.next = newNode;
      this.length += 1;

      return newNode;
    }
  }

  &amp;#x2F;&amp;#x2F; remove from a specific index
  remove(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else if (index === 0) {
      return this.shift();
    } else if (index === this.length - 1) {
      return this.pop();
    } else {
      const preNodeToRemove = this.get(index - 1);
      const nodeToRemove = preNodeToRemove.next;
      preNodeToRemove.next = nodeToRemove.next;
      this.length -= 1;

      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you like this &amp;quot;tiny steps&amp;quot; approach?&lt;&#x2F;li&gt;
&lt;li&gt;Are you interested in other data structures, e.g. Doubly Linked List, Stack, Queue?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Remove</title>
        <published>2019-12-01T00:00:00+00:00</published>
        <updated>2019-12-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-12-01/" type="text/html"/>
        <id>https://miku86.com/2019-12-01/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-insert&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to insert a new node at any a specific index.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to remove a node at any specific index.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with code that has &lt;code&gt;push&lt;&#x2F;code&gt;, &lt;code&gt;shift&lt;&#x2F;code&gt;, &lt;code&gt;pop&lt;&#x2F;code&gt; and &lt;code&gt;get&lt;&#x2F;code&gt;, because we can reuse these methods:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;push&lt;&#x2F;code&gt; to add some nodes to test the stuff&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;shift&lt;&#x2F;code&gt; to remove at the beginning of the List&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;pop&lt;&#x2F;code&gt; to remove at the end of the List&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;get&lt;&#x2F;code&gt; to get a specific node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
    } else {
      this.tail.next = newNode;
    }

    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  shift() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.head;
      this.head = this.head.next;
      this.length -= 1;

      if (!this.length) {
        this.tail = null;
      }

      return nodeToRemove;
    }
  }

  pop() {
    if (!this.tail) {
      return null;
    } else {
      let currentNode = this.head;
      let preTail = this.head;
      while (currentNode.next) {
        preTail = currentNode;
        currentNode = currentNode.next;
      }
      this.tail = preTail;
      this.tail.next = null;
      this.length -= 1;
      if (!this.length) {
        this.head = null;
        this.tail = null;
      }
      return currentNode;
    }
  }

  get(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let count = 0;
      let currentNode = this.head;

      while (count &amp;lt; index) {
        currentNode = currentNode.next;
        count += 1;
      }

      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If we want to remove a node &amp;quot;outside&amp;quot; the List (index is less than 0 or greater than or equal to the length of the current List):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If we want to remove a node from the beginning of the List (index is 0):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can use our &lt;code&gt;shift&lt;&#x2F;code&gt; method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If we want to remove a node from the end of the List (index is length - 1):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can use our &lt;code&gt;pop&lt;&#x2F;code&gt; method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;find the node before the nodeToRemove&lt;&#x2F;li&gt;
&lt;li&gt;set the found node&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; as the nodeToRemove&lt;&#x2F;li&gt;
&lt;li&gt;set the nodeToRemove&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; as the &lt;code&gt;next&lt;&#x2F;code&gt; of the node before nodeToRemove&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;current List: A -&amp;gt; B -&amp;gt; C&lt;&#x2F;li&gt;
&lt;li&gt;we want to remove &lt;code&gt;B&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;desired List: A -&amp;gt; C&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;find the node before &lt;code&gt;B&lt;&#x2F;code&gt; (=&lt;code&gt;A&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;point &lt;code&gt;A&lt;&#x2F;code&gt;&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; to &lt;code&gt;B&lt;&#x2F;code&gt;&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; (=&lt;code&gt;C&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
    } else {
      this.tail.next = newNode;
    }

    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  shift() {
    if (!this.length) {
      return null;
    } else {
      const nodeToRemove = this.head;
      this.head = this.head.next;
      this.length -= 1;

      if (!this.length) {
        this.tail = null;
      }

      return nodeToRemove;
    }
  }

  pop() {
    if (!this.tail) {
      return null;
    } else {
      let currentNode = this.head;
      let preTail = this.head;
      while (currentNode.next) {
        preTail = currentNode;
        currentNode = currentNode.next;
      }
      this.tail = preTail;
      this.tail.next = null;
      this.length -= 1;
      if (!this.length) {
        this.head = null;
        this.tail = null;
      }
      return currentNode;
    }
  }

  get(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let count = 0;
      let currentNode = this.head;

      while (count &amp;lt; index) {
        currentNode = currentNode.next;
        count += 1;
      }

      return currentNode;
    }
  }

  remove(index) {
    &amp;#x2F;&amp;#x2F; remove a node &amp;quot;outside&amp;quot; the List (=&amp;gt; invalid)
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else if (index === 0) {
      &amp;#x2F;&amp;#x2F; remove a node from the beginning of the List
      return this.shift();
    } else if (index === this.length - 1) {
      &amp;#x2F;&amp;#x2F; remove a node from the end of the List
      return this.pop();
    } else {
      &amp;#x2F;&amp;#x2F; find the node before the nodeToRemove
      const preNodeToRemove = this.get(index - 1);

      &amp;#x2F;&amp;#x2F; we want to return the removed node later
      const nodeToRemove = preNodeToRemove.next;

      &amp;#x2F;&amp;#x2F; set the node after the node to remove (=C) as the new node after the node before the node to remove (=A)
      preNodeToRemove.next = nodeToRemove.next; &amp;#x2F;&amp;#x2F; from A -&amp;gt; B -&amp;gt; C to A -&amp;gt; C

      &amp;#x2F;&amp;#x2F; decrease the List&amp;#x27;s length by 1
      this.length -= 1;

      &amp;#x2F;&amp;#x2F; return the new node
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List&#x27;s &lt;code&gt;remove&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();
newSLL.push(&amp;quot;A&amp;quot;);
newSLL.push(&amp;quot;B&amp;quot;);
newSLL.push(&amp;quot;C&amp;quot;);

console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 3,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;A&amp;#x27;, next: Node { value: &amp;#x27;B&amp;#x27;, next: [Node] } },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;C&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

console.log(newSLL.remove(1));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;B&amp;#x27;, next: Node { value: &amp;#x27;C&amp;#x27;, next: null } }

console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;A&amp;#x27;, next: Node { value: &amp;#x27;C&amp;#x27;, next: null } },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;C&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Insert</title>
        <published>2019-11-30T00:00:00+00:00</published>
        <updated>2019-11-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-30/" type="text/html"/>
        <id>https://miku86.com/2019-11-30/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-set&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to update&#x2F;set a specific node.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to insert a new node at any specific index.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with code that has &lt;code&gt;push&lt;&#x2F;code&gt;, &lt;code&gt;unshift&lt;&#x2F;code&gt; and &lt;code&gt;get&lt;&#x2F;code&gt;, because we can reuse these methods.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
    } else {
      this.tail.next = newNode;
    }

    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  unshift(value) {
    const newHead = new Node(value);

    if (!this.length) {
      this.head = newHead;
      this.tail = newHead;
    } else {
      newHead.next = this.head;
      this.head = newHead;
    }

    this.length += 1;

    return newHead;
  }

  get(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let count = 0;
      let currentNode = this.head;

      while (count &amp;lt; index) {
        currentNode = currentNode.next;
        count += 1;
      }

      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If we want to add a node &amp;quot;outside&amp;quot; the List (less than 0 or greater than the length of the current List):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If we want to add a node at the beginning of the List (index is 0):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can use our &lt;code&gt;unshift&lt;&#x2F;code&gt; method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If we want to add a node at the end of the List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;we can use our &lt;code&gt;push&lt;&#x2F;code&gt; method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;All remaining cases:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;put it between the node before the new node&#x27;s place and the node, that is currently at this place&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;current List: A -&amp;gt; B&lt;&#x2F;li&gt;
&lt;li&gt;desired List: A -&amp;gt; N -&amp;gt; B&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Steps:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create new node &lt;code&gt;N&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;point &lt;code&gt;N&lt;&#x2F;code&gt;&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; to &lt;code&gt;B&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;point &lt;code&gt;A&lt;&#x2F;code&gt;&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; to &lt;code&gt;N&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
    } else {
      this.tail.next = newNode;
    }

    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  unshift(value) {
    const newHead = new Node(value);

    if (!this.length) {
      this.head = newHead;
      this.tail = newHead;
    } else {
      newHead.next = this.head;
      this.head = newHead;
    }

    this.length += 1;

    return newHead;
  }

  get(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let count = 0;
      let currentNode = this.head;

      while (count &amp;lt; index) {
        currentNode = currentNode.next;
        count += 1;
      }

      return currentNode;
    }
  }

  insert(index, value) {
    &amp;#x2F;&amp;#x2F; add a node &amp;quot;outside&amp;quot; the List (=&amp;gt; invalid)
    if (index &amp;lt; 0 || index &amp;gt; this.length) {
      return null;
    } else if (index === 0) {
      &amp;#x2F;&amp;#x2F; add a node to the beginning of the List
      return this.unshift(value);
    } else if (index === this.length) {
      &amp;#x2F;&amp;#x2F; add a node to the end of the List
      return this.push(value);
    } else {
      &amp;#x2F;&amp;#x2F; get the node before the new node&amp;#x27;s desired place (because it has to point to the new node soon)
      const preDesiredPlace = this.get(index - 1);
      &amp;#x2F;&amp;#x2F; create a new node
      const newNode = new Node(value);
      &amp;#x2F;&amp;#x2F; the new node should point to the node, that is currently at the new node&amp;#x27;s desired place
      newNode.next = preDesiredPlace.next;
      &amp;#x2F;&amp;#x2F; the node before the new node&amp;#x27;s desired place should point to the new node
      preDesiredPlace.next = newNode;
      &amp;#x2F;&amp;#x2F; increase the List&amp;#x27;s length by 1
      this.length += 1;
      &amp;#x2F;&amp;#x2F; return the new node
      return newNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List&#x27;s &lt;code&gt;insert&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();
console.log(newSLL.insert(0, &amp;quot;A&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;A&amp;#x27;, next: null }

console.log(newSLL.insert(1, &amp;quot;B&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;B&amp;#x27;, next: null }

console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;A&amp;#x27;, next: Node { value: &amp;#x27;B&amp;#x27;, next: null } },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;B&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

console.log(newSLL.insert(1, &amp;quot;N (between A and B)&amp;quot;));
&amp;#x2F;&amp;#x2F; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;N (between A and B)&amp;#x27;,
&amp;#x2F;&amp;#x2F;   next: Node { value: &amp;#x27;B&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 3,
&amp;#x2F;&amp;#x2F;   head: Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;A&amp;#x27;,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;N (between A and B)&amp;#x27;, next: [Node] }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;B&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to remove a node at a specific index. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h3&gt;
&lt;p&gt;We are doing it like:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;point &lt;code&gt;N&lt;&#x2F;code&gt;&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; to &lt;code&gt;B&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;point &lt;code&gt;A&lt;&#x2F;code&gt;&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; to &lt;code&gt;N&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;What would happen, if we&#x27;d switch these steps?&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Set</title>
        <published>2019-11-28T00:00:00+00:00</published>
        <updated>2019-11-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-28/" type="text/html"/>
        <id>https://miku86.com/2019-11-28/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-get&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to get a specific node by its index.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to update &#x2F; set a specific node.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-get&quot;&gt;after we added &lt;code&gt;get()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, because we can use our &lt;code&gt;get&lt;&#x2F;code&gt; method to get the node we want to change.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (this.length &amp;gt; 0) {
      this.tail.next = newNode;
    } else {
      this.head = newNode;
    }
    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  get(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode = this.head;
      let count = 0;

      while (count &amp;lt; index) {
        currentNode = currentNode.next;
        count += 1;
      }

      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;Because we will use our &lt;code&gt;get&lt;&#x2F;code&gt; method to get the node, this is straight-forward:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;get the node at the desired index&lt;&#x2F;li&gt;
&lt;li&gt;if the node does exist, set its value to the desired new value and return it&lt;&#x2F;li&gt;
&lt;li&gt;if the node does not exist, return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (this.length &amp;gt; 0) {
      this.tail.next = newNode;
    } else {
      this.head = newNode;
    }
    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  get(index) {
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      let currentNode = this.head;
      let count = 0;

      while (count &amp;lt; index) {
        currentNode = currentNode.next;
        count += 1;
      }

      return currentNode;
    }
  }

  set(index, value) {
    &amp;#x2F;&amp;#x2F; get the node at the desired index
    const currentNode = this.get(index);
    &amp;#x2F;&amp;#x2F; if the node does exist
    if (currentNode) {
      &amp;#x2F;&amp;#x2F; set its value to the desired new value
      currentNode.value = value;
      &amp;#x2F;&amp;#x2F; and return it
      return currentNode;
    } else {
      &amp;#x2F;&amp;#x2F; if the node does not exist, return null
      return null;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List&#x27;s &lt;code&gt;set&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();
&amp;#x2F;&amp;#x2F; show List, should be empty
console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList { length: 0, head: null, tail: null }

&amp;#x2F;&amp;#x2F; change a node that does not exist =&amp;gt; return null and the empty List
console.log(newSLL.set(0, &amp;quot;new 0&amp;quot;));
&amp;#x2F;&amp;#x2F; null
console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList { length: 0, head: null, tail: null }

&amp;#x2F;&amp;#x2F; add two nodes and updated both =&amp;gt; return updated nodes and show updated List
newSLL.push(&amp;quot;0&amp;quot;);
newSLL.push(&amp;quot;1&amp;quot;);
console.log(newSLL.set(0, &amp;quot;new 0&amp;quot;)); &amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new 0&amp;#x27;, next: Node { value: &amp;#x27;1&amp;#x27;, next: null } }
console.log(newSLL.set(1, &amp;quot;new 1&amp;quot;)); &amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;new 1&amp;#x27;, next: null }
console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;new 0&amp;#x27;, next: Node { value: &amp;#x27;new 1&amp;#x27;, next: null } },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;new 1&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to insert a new node at a specific index. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Get</title>
        <published>2019-11-27T00:00:00+00:00</published>
        <updated>2019-11-27T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-27/" type="text/html"/>
        <id>https://miku86.com/2019-11-27/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-shift&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to shift &#x2F; remove a node from the beginning of our Singly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to get any specific node by its index.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-push&quot;&gt;after we added &lt;code&gt;push()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, because we want to keep the code as simple as possible to understand. We need &lt;code&gt;push()&lt;&#x2F;code&gt; to add some nodes to the List.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (this.length &amp;gt; 0) {
      this.tail.next = newNode;
    } else {
      this.head = newNode;
    }
    this.tail = newNode;
    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If the index is negative or equal to or greater than the length of the List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Else:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;start at the beginning of the List&lt;&#x2F;li&gt;
&lt;li&gt;go to the next node [index]-times&lt;&#x2F;li&gt;
&lt;li&gt;return this node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Examples:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;index &amp;lt; 0: return null&lt;&#x2F;li&gt;
&lt;li&gt;index = 0: return &lt;code&gt;head&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;index &amp;gt;= List.length: return null&lt;&#x2F;li&gt;
&lt;li&gt;remaining cases: go to head, go index-times to the next node &amp;amp; return this node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null if the List doesn&#x27;t have the desired node or go index-times to the next node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (this.length &amp;gt; 0) {
      this.tail.next = newNode;
    } else {
      this.head = newNode;
    }
    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  get(index) {
    &amp;#x2F;&amp;#x2F; return null if index is negative or equal to or greater than the length of the List
    if (index &amp;lt; 0 || index &amp;gt;= this.length) {
      return null;
    } else {
      &amp;#x2F;&amp;#x2F; start at the beginning of the List
      let currentNode = this.head;
      &amp;#x2F;&amp;#x2F; keep track how many times we went to the next node
      let count = 0;

      &amp;#x2F;&amp;#x2F; as long as the current count is smaller than the desired node&amp;#x27;s index
      while (count &amp;lt; index) {
        &amp;#x2F;&amp;#x2F; set the next node as the currentNode
        currentNode = currentNode.next;
        &amp;#x2F;&amp;#x2F; increase the count by 1
        count += 1;
      }

      &amp;#x2F;&amp;#x2F; return this node
      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List&#x27;s &lt;code&gt;get&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();

&amp;#x2F;&amp;#x2F; show List, should be empty
console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList { length: 0, head: null, tail: null }

&amp;#x2F;&amp;#x2F; add three nodes
newSLL.push(&amp;quot;0&amp;quot;);
newSLL.push(&amp;quot;1&amp;quot;);
newSLL.push(&amp;quot;2&amp;quot;);

&amp;#x2F;&amp;#x2F; there is no node with a negative index
console.log(newSLL.get(-1));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; there is no node with that high of an index
console.log(newSLL.get(3));
&amp;#x2F;&amp;#x2F; null

&amp;#x2F;&amp;#x2F; show me the first node
console.log(newSLL.get(0));
&amp;#x2F;&amp;#x2F; Node {
&amp;#x2F;&amp;#x2F;   value: &amp;#x27;0&amp;#x27;,
&amp;#x2F;&amp;#x2F;   next: Node { value: &amp;#x27;1&amp;#x27;, next: Node { value: &amp;#x27;2&amp;#x27;, next: null } }
&amp;#x2F;&amp;#x2F; }

&amp;#x2F;&amp;#x2F; show me the second node
console.log(newSLL.get(1));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;1&amp;#x27;, next: Node { value: &amp;#x27;2&amp;#x27;, next: null } }

&amp;#x2F;&amp;#x2F; show me the third node
console.log(newSLL.get(2));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;2&amp;#x27;, next: null }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to give a specific node a new value. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Shift</title>
        <published>2019-11-26T00:00:00+00:00</published>
        <updated>2019-11-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-26/" type="text/html"/>
        <id>https://miku86.com/2019-11-26/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-unshift&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to unshift &#x2F; add something to the beginning of our Singly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to shift something from the list. &lt;code&gt;Shift&lt;&#x2F;code&gt; means &lt;code&gt;remove something from the beginning&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-push&quot;&gt;after we added &lt;code&gt;push()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, because we want to keep the code as simple as possible to understand. We need &lt;code&gt;push()&lt;&#x2F;code&gt; to add some nodes to the List.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (this.length &amp;gt; 0) {
      this.tail.next = newNode;
    } else {
      this.head = newNode;
    }
    this.tail = newNode;
    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If there is currently NO other node in the Singly Linked List (so it is currently empty):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return null, because we can&#x27;t remove anything from the beginning of the Singly Linked list&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If there is 1 node in the Singly Linked List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;set the current &lt;code&gt;head&lt;&#x2F;code&gt; as the node we want to remove (&lt;code&gt;nodeToRemove&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;set the the 2nd node as the new &lt;code&gt;head&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;decrease the List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;set the &lt;code&gt;tail&lt;&#x2F;code&gt; to &lt;code&gt;null&lt;&#x2F;code&gt;, because the List is empty now&lt;&#x2F;li&gt;
&lt;li&gt;return the &lt;code&gt;nodeToRemove&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If there is more than 1 node in the Singly Linked List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;set the current &lt;code&gt;head&lt;&#x2F;code&gt; as the node we want to remove (&lt;code&gt;nodeToRemove&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;set the the 2nd node as the new &lt;code&gt;head&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;decrease the List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the &lt;code&gt;nodeToRemove&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Examples:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;0 nodes: before: null (head &amp;amp; tail) =&amp;gt; after: null (head &amp;amp; tail) (couldn&#x27;t remove anything)&lt;&#x2F;li&gt;
&lt;li&gt;1 node: before: A (head &amp;amp; tail) =&amp;gt; after: null (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;n nodes: before: A (head) -&amp;gt; B -&amp;gt; ... -&amp;gt; n (tail) =&amp;gt; after: B (head) -&amp;gt; ... -&amp;gt; n (tail)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;there is only one difference: an additional step if there was only 1 node in the List&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
    } else {
      this.tail.next = newNode;
    }

    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  shift() {
    &amp;#x2F;&amp;#x2F; we can&amp;#x27;t remove anything from an empty List
    if (!this.length) {
      return null;
    } else {
      &amp;#x2F;&amp;#x2F; set the current `head` as the node we want to remove (`nodeToRemove`)
      const nodeToRemove = this.head;

      &amp;#x2F;&amp;#x2F; set the 2nd node as the new `head`
      this.head = this.head.next;

      &amp;#x2F;&amp;#x2F; decrease the List&amp;#x27;s length by 1
      this.length -= 1;

      &amp;#x2F;&amp;#x2F; if the List is empty now, there isn&amp;#x27;t a tail anymore
      if (!this.length) {
        this.tail = null;
      }

      &amp;#x2F;&amp;#x2F; return the `nodeToRemove`
      return nodeToRemove;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List &lt;code&gt;shift&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();

&amp;#x2F;&amp;#x2F; we can&amp;#x27;t remove from an empty list
console.log(newSLL.shift());

&amp;#x2F;&amp;#x2F; add one node and remove it
newSLL.push(&amp;quot;1st node&amp;quot;);
console.log(newSLL.shift()); &amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;1st node&amp;#x27;, next: null }
console.log(newSLL); &amp;#x2F;&amp;#x2F; SinglyLinkedList { length: 0, head: null, tail: null }

&amp;#x2F;&amp;#x2F; add two nodes and remove the first
newSLL.push(&amp;quot;new 1st node&amp;quot;);
newSLL.push(&amp;quot;2nd node&amp;quot;);
console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 2,
&amp;#x2F;&amp;#x2F;   head: Node {
&amp;#x2F;&amp;#x2F;     value: &amp;#x27;new 1st node&amp;#x27;,
&amp;#x2F;&amp;#x2F;     next: Node { value: &amp;#x27;2nd node&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F;   },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;2nd node&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

console.log(newSLL.shift());
&amp;#x2F;&amp;#x2F; Node {
&amp;#x2F;&amp;#x2F;  value: &amp;#x27;new 1st node&amp;#x27;,
&amp;#x2F;&amp;#x2F;  next: Node { value: &amp;#x27;2nd node&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }

console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList {
&amp;#x2F;&amp;#x2F;   length: 1,
&amp;#x2F;&amp;#x2F;   head: Node { value: &amp;#x27;2nd node&amp;#x27;, next: null },
&amp;#x2F;&amp;#x2F;   tail: Node { value: &amp;#x27;2nd node&amp;#x27;, next: null }
&amp;#x2F;&amp;#x2F; }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to get a specific node by its index. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Unshift</title>
        <published>2019-11-18T00:00:00+00:00</published>
        <updated>2019-11-18T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-18/" type="text/html"/>
        <id>https://miku86.com/2019-11-18/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-pop&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to pop a new node from the end of our Singly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to unshift something to the list. &lt;code&gt;Unshift&lt;&#x2F;code&gt; means &lt;code&gt;add something to the beginning&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;p&gt;We start with the code &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-setup&quot;&gt;from the setup&lt;&#x2F;a&gt;, without &lt;code&gt;push&lt;&#x2F;code&gt; and &lt;code&gt;pop&lt;&#x2F;code&gt;, because we want to keep the code as simple as possible to understand.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If there is currently NO other node in the Singly Linked List (so it is currently empty):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the Singly Linked List&#x27;s &lt;code&gt;tail&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the Singly Linked List&#x27;s &lt;code&gt;head&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;increase the Singly Linked List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If there is at least 1 node in the Singly Linked List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node&lt;&#x2F;li&gt;
&lt;li&gt;set the new node&#x27;s &lt;code&gt;next&lt;&#x2F;code&gt; to the Singly Linked List&#x27;s current &lt;code&gt;head&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;set the new node as the Singly Linked List&#x27;s &lt;code&gt;head&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;increase the Singly Linked List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Examples:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;0 nodes: before: null (head &amp;amp; tail) =&amp;gt; after: A (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;1 node: before: A (head &amp;amp; tail) =&amp;gt; after: A-1 (head) -&amp;gt; A (tail)&lt;&#x2F;li&gt;
&lt;li&gt;n nodes: before: A (head) -&amp;gt; ... -&amp;gt; n (tail) =&amp;gt; after: A-1 (head) -&amp;gt; A -&amp;gt; ... -&amp;gt; n (tail)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Differences:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;there is only one difference: the step after creating a new node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  unshift(value) {
    &amp;#x2F;&amp;#x2F; create a new node
    const newNode = new Node(value);

    &amp;#x2F;&amp;#x2F; check if Singly Linked List is empty
    if (!this.length) {
      &amp;#x2F;&amp;#x2F; set the new node as the Singly Linked List&amp;#x27;s `tail`
      this.tail = newNode;
    } else {
      &amp;#x2F;&amp;#x2F; set the new node&amp;#x27;s `next` to the Singly Linked List&amp;#x27;s current `head`
      newNode.next = this.head;
    }

    &amp;#x2F;&amp;#x2F; set the new node as the Singly Linked List&amp;#x27;s `head`
    this.head = newNode;

    &amp;#x2F;&amp;#x2F; increase the Singly Linked List&amp;#x27;s length by 1
    this.length += 1;

    &amp;#x2F;&amp;#x2F; return the new node
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List &lt;code&gt;unshift&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();

&amp;#x2F;&amp;#x2F; should be empty
console.log(newSLL);
&amp;#x2F;&amp;#x2F; SinglyLinkedList { length: 0, head: null, tail: null }

console.log(newSLL.unshift(&amp;quot;1&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;1&amp;#x27;, next: null }

&amp;#x2F;&amp;#x2F; should be a list with the new node with value 1
console.log(newSLL);
&amp;#x2F;*
 *  SinglyLinkedList {
 *    length: 1,
 *    head: Node { value: &amp;#x27;1&amp;#x27;, next: null },
 *    tail: Node { value: &amp;#x27;1&amp;#x27;, next: null }
 *  }
 *&amp;#x2F;

console.log(newSLL.unshift(&amp;quot;2&amp;quot;));
&amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;2&amp;#x27;, next: Node { value: &amp;#x27;1&amp;#x27;, next: null } }

&amp;#x2F;&amp;#x2F; should be a list with the new node with value 2 and 1 (from the last unshift)
console.log(newSLL);
&amp;#x2F;*
 *  SinglyLinkedList {
 *    length: 2,
 *    head: Node { value: &amp;#x27;2&amp;#x27;, next: Node { value: &amp;#x27;1&amp;#x27;, next: null } },
 *    tail: Node { value: &amp;#x27;1&amp;#x27;, next: null }
 *  }
 *&amp;#x2F;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to remove a node from the beginning of the Singly Linked List. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Pop</title>
        <published>2019-11-17T00:00:00+00:00</published>
        <updated>2019-11-17T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-17/" type="text/html"/>
        <id>https://miku86.com/2019-11-17/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-push&quot;&gt;Last time&lt;&#x2F;a&gt;, we learned how to push a new node to the end of our Singly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to pop something from the list. &lt;code&gt;Pop&lt;&#x2F;code&gt; means &lt;code&gt;remove something from the end&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (this.length &amp;gt; 0) {
      this.tail.next = newNode;
    } else {
      this.head = newNode;
    }
    this.tail = newNode;
    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If there is currently NO other node in the Singly Linked List (so it is currently empty):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;return &lt;code&gt;null&lt;&#x2F;code&gt;, because we can&#x27;t remove a node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If there is 1 node in the Singly Linked List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;find the second to last node (it should become the new tail)&lt;&#x2F;li&gt;
&lt;li&gt;set its &lt;code&gt;next&lt;&#x2F;code&gt; to &lt;code&gt;null&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;set it as &lt;code&gt;tail&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;decrease the Singly Linked List&#x27;s &lt;code&gt;length&lt;&#x2F;code&gt; by 1&lt;&#x2F;li&gt;
&lt;li&gt;set the Singly Linked List&#x27;s &lt;code&gt;head&lt;&#x2F;code&gt; and &lt;code&gt;tail&lt;&#x2F;code&gt; to &lt;code&gt;null&lt;&#x2F;code&gt;, because it is empty now&lt;&#x2F;li&gt;
&lt;li&gt;return the popped node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If there is more than 1 node in the Singly Linked List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;find the second to last node (it should become the new tail)&lt;&#x2F;li&gt;
&lt;li&gt;set its &lt;code&gt;next&lt;&#x2F;code&gt; to &lt;code&gt;null&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;set it as &lt;code&gt;tail&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;decrease the Singly Linked List&#x27;s &lt;code&gt;length&lt;&#x2F;code&gt; by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the popped node&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Examples:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;0 nodes: before: null (head &amp;amp; tail) =&amp;gt; after: null (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;1 node: before: A (head &amp;amp; tail) =&amp;gt; after: null (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;2 nodes: before: A (head) -&amp;gt; B (tail) =&amp;gt; after: A (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;n nodes: before: A (head) -&amp;gt; ... -&amp;gt; n-1 -&amp;gt; n (tail) =&amp;gt; after: A (head) -&amp;gt; ... -&amp;gt; n-1 (tail)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (!this.length) {
      this.head = newNode;
    } else {
      this.tail.next = newNode;
    }

    this.tail = newNode;
    this.length += 1;
    return newNode;
  }

  pop() {
    &amp;#x2F;&amp;#x2F; no node in the list, therefore return null
    if (!this.length) {
      return null;
    } else {
      &amp;#x2F;*
       * find the second to last node (it should become the new tail):
       * - set the current head as currentNode (we always have to start from the List&amp;#x27;s head node)
       * - set the current head as secondToLastNode (we can&amp;#x27;t go back a node, therefore we have to save the second to last)
       * - as long as the current node has a next node (so it is not the last node)
       * - then set the current node to the second to last
       * - then set the current node&amp;#x27;s `next` as the current node
       *&amp;#x2F;
      let currentNode = this.head;
      let secondToLastNode = this.head;
      while (currentNode.next) {
        secondToLastNode = currentNode;
        currentNode = currentNode.next;
      }
      &amp;#x2F;&amp;#x2F; set the second to last node&amp;#x27;s `next` to `null` (the second to last should &amp;quot;cut&amp;quot; its connection to the next node)
      secondToLastNode.next = null;
      &amp;#x2F;&amp;#x2F; set it as `tail`
      this.tail = secondToLastNode;
      &amp;#x2F;&amp;#x2F; decrease the Singly Linked List&amp;#x27;s `length` by 1
      this.length -= 1;
      &amp;#x2F;&amp;#x2F; if the Singly Linked List now is empty, set its `head` and `tail` to `null`
      if (!this.length) {
        this.head = null;
        this.tail = null;
      }
      &amp;#x2F;&amp;#x2F; return the popped node (found some lines above)
      return currentNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List &lt;code&gt;pop&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();
newSLL.push(&amp;quot;1&amp;quot;);
newSLL.push(&amp;quot;2&amp;quot;);
console.log(newSLL);
&amp;#x2F;* SinglyLinkedList {
 *   length: 2,
 *   head: Node { value: &amp;#x27;1&amp;#x27;, next: Node { value: &amp;#x27;2&amp;#x27;, next: null } },
 *   tail: Node { value: &amp;#x27;2&amp;#x27;, next: null }
 * }
 *&amp;#x2F;
console.log(newSLL.pop()); &amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;2&amp;#x27;, next: null }
console.log(newSLL.pop()); &amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;1&amp;#x27;, next: null }
console.log(newSLL.pop()); &amp;#x2F;&amp;#x2F; null
console.log(newSLL); &amp;#x2F;&amp;#x2F; SinglyLinkedList { length: 0, head: null, tail: null }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to add a node to the beginning of the Singly Linked List. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Push</title>
        <published>2019-11-16T00:00:00+00:00</published>
        <updated>2019-11-16T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-16/" type="text/html"/>
        <id>https://miku86.com/2019-11-16/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-setup&quot;&gt;Last time&lt;&#x2F;a&gt;, we setup our Singly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we learn how to push something to the list. &lt;code&gt;Push&lt;&#x2F;code&gt; means &lt;code&gt;add something to the end&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;recap-from-last-time&quot;&gt;Recap from &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-setup&quot;&gt;last time&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;we created a class &lt;code&gt;Node&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;we created a class &lt;code&gt;Singly Linked List&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;we learned how to create an instance of the &lt;code&gt;Node&lt;&#x2F;code&gt; class&lt;&#x2F;li&gt;
&lt;li&gt;we learned how to create an instance of the &lt;code&gt;Singly Linked List&lt;&#x2F;code&gt; class&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;current-code&quot;&gt;Current Code&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; name of the class
class Node {
  &amp;#x2F;&amp;#x2F; the constructor runs when using the class with `new` (see later)
  constructor(value) {
    &amp;#x2F;&amp;#x2F; set this nodes value property to the instantiation value
    this.value = value;
    &amp;#x2F;&amp;#x2F; set this nodes next property to `null`
    this.next = null;
  }
}

&amp;#x2F;&amp;#x2F; name of the class
class SinglyLinkedList {
  &amp;#x2F;&amp;#x2F; the constructor runs when using the class with `new`
  constructor() {
    &amp;#x2F;&amp;#x2F; set this lists length property to `0`
    this.length = 0;
    &amp;#x2F;&amp;#x2F; set this lists head property to `null`
    this.head = null;
    &amp;#x2F;&amp;#x2F; set this lists tail property to `null`
    this.tail = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;thoughts&quot;&gt;Thoughts&lt;&#x2F;h2&gt;
&lt;p&gt;First, we should think about the constraints and possibilities:&lt;&#x2F;p&gt;
&lt;p&gt;If there is already at least one other node in the Singly Linked List:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node with an input value&lt;&#x2F;li&gt;
&lt;li&gt;point the current tails &lt;code&gt;next&lt;&#x2F;code&gt; property to the new node (so the new node comes after the current tail)&lt;&#x2F;li&gt;
&lt;li&gt;set the Singly Linked List&#x27;s &lt;code&gt;tail&lt;&#x2F;code&gt; to the new node&lt;&#x2F;li&gt;
&lt;li&gt;increase the Singly Linked List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node (so that we knew what we added)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If there is currently NO other node in the Singly Linked List (so it is currently empty):&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;create a new node with an input value&lt;&#x2F;li&gt;
&lt;li&gt;set the Singly Linked List&#x27;s &lt;code&gt;head&lt;&#x2F;code&gt; to the new node&lt;&#x2F;li&gt;
&lt;li&gt;set the Singly Linked List&#x27;s &lt;code&gt;tail&lt;&#x2F;code&gt; to the new node&lt;&#x2F;li&gt;
&lt;li&gt;increase the Singly Linked List&#x27;s length by 1&lt;&#x2F;li&gt;
&lt;li&gt;return the new node (so that we knew what we added)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The differences?&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;if the Singly Linked List is empty, we need a head (the new node, because it is the only node)&lt;&#x2F;li&gt;
&lt;li&gt;if the Singly Linked List already has at least one node, the last node should point to the new node and this new last node is the new tail&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Example:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;0 nodes: before: null (head &amp;amp; tail) =&amp;gt; after: A (head &amp;amp; tail)&lt;&#x2F;li&gt;
&lt;li&gt;1 node: before: A (head &amp;amp; tail) =&amp;gt; after: A (head) -&amp;gt; B (tail)&lt;&#x2F;li&gt;
&lt;li&gt;2 nodes: before: A (head) -&amp;gt; B (tail) =&amp;gt; after: A (head) -&amp;gt; B -&amp;gt; C (tail)&lt;&#x2F;li&gt;
&lt;li&gt;n nodes: before: A (head) -&amp;gt; ... -&amp;gt; n (tail) =&amp;gt; after: A (head) -&amp;gt; ... -&amp;gt; n -&amp;gt; n+1 (tail)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;So &lt;code&gt;A&lt;&#x2F;code&gt; always stays the head, only if we got 0 nodes, we have to set &lt;code&gt;A&lt;&#x2F;code&gt; as the new &lt;code&gt;head&lt;&#x2F;code&gt;.
In every other situation, we have to point the current &lt;code&gt;tail&lt;&#x2F;code&gt; to the new node and make the new node the new &lt;code&gt;tail&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;implementation-long-version-no-dry&quot;&gt;Implementation (Long version, no DRY)&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Comments from section &lt;code&gt;Thoughts&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    &amp;#x2F;*
     * 1. If there is already at least one other node in the Singly Linked List
     *&amp;#x2F;
    if (this.length &amp;gt; 0) {
      &amp;#x2F;&amp;#x2F; create a new node with an input value
      const newNode = new Node(value);
      &amp;#x2F;&amp;#x2F; point the current tails `next` property to the new node
      this.tail.next = newNode;
      &amp;#x2F;&amp;#x2F; set the Singly Linked List&amp;#x27;s `tail` to the new node
      this.tail = newNode;
      &amp;#x2F;&amp;#x2F; increase the Singly Linked List&amp;#x27;s length by 1
      this.length += 1;
      &amp;#x2F;&amp;#x2F; return the new node
      return newNode;
    } else {
      &amp;#x2F;*
       * 2. If there is currently NO other node in the Singly Linked List (so it is currently empty):
       *&amp;#x2F;
      &amp;#x2F;&amp;#x2F; create a new node with an input value
      const newNode = new Node(value);
      &amp;#x2F;&amp;#x2F; set the Singly Linked List&amp;#x27;s `head` to the new node
      this.head = newNode;
      &amp;#x2F;&amp;#x2F; set the Singly Linked List&amp;#x27;s `tail` to the new node
      this.tail = newNode;
      &amp;#x2F;&amp;#x2F; increase the Singly Linked List&amp;#x27;s length by 1
      this.length += 1;
      &amp;#x2F;&amp;#x2F; return the new node (so that we knew what we added)
      return newNode;
    }
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;implementation-short-version-dry&quot;&gt;Implementation (Short version, DRY)&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;we have a lot of duplicate code, because most of the logic is the same&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;class Node {
  constructor(value) {
    this.value = value;
    this.next = null;
  }
}

class SinglyLinkedList {
  constructor() {
    this.length = 0;
    this.head = null;
    this.tail = null;
  }

  push(value) {
    const newNode = new Node(value);
    if (this.length &amp;gt; 0) {
      this.tail.next = newNode;
    } else {
      this.head = newNode;
    }
    this.tail = newNode;
    this.length += 1;
    return newNode;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;result&quot;&gt;Result&lt;&#x2F;h2&gt;
&lt;p&gt;Let&#x27;s have a look how to use the Singly Linked List &lt;code&gt;push&lt;&#x2F;code&gt; method and its results.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSLL = new SinglyLinkedList();
console.log(newSLL);
&amp;#x2F;*
 * SinglyLinkedList {
 *   length: 0,
 *   head: null,
 *   tail: null
 * }
 *&amp;#x2F;

newSLL.push(&amp;quot;A&amp;quot;);
console.log(newSLL);
&amp;#x2F;*
 * SinglyLinkedList {
 *   length: 1,
 *   head: Node { value: &amp;#x27;A&amp;#x27;, next: null },
 *   tail: Node { value: &amp;#x27;A&amp;#x27;, next: null }
 * }
 *&amp;#x2F;

newSLL.push(&amp;quot;B&amp;quot;);
console.log(newSLL);
&amp;#x2F;*
 * SinglyLinkedList {
 *   length: 2,
 *   head: Node { value: &amp;#x27;A&amp;#x27;, next: Node { value: &amp;#x27;B&amp;#x27;, next: null } },
 *   tail: Node { value: &amp;#x27;B&amp;#x27;, next: null }
 * }
 *&amp;#x2F;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to remove a node from the end of the Singly Linked List. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List: Setup</title>
        <published>2019-11-15T00:00:00+00:00</published>
        <updated>2019-11-15T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-15/" type="text/html"/>
        <id>https://miku86.com/2019-11-15/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-intro&quot;&gt;Last time&lt;&#x2F;a&gt;, we talked about the theory behind a Singly Linked List.&lt;&#x2F;p&gt;
&lt;p&gt;Today, we start implementing it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;recap-from-last-time&quot;&gt;Recap from &lt;a href=&quot;&#x2F;blog&#x2F;js-ds-singly-linked-list-intro&quot;&gt;last time&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;real life example: a treasure hunt, where you have a starting point and have to seek places and solve riddles in a particular order; the current place knows about the next place, but the current place doesn&#x27;t know about the previous place&lt;&#x2F;li&gt;
&lt;li&gt;consists of nodes&lt;&#x2F;li&gt;
&lt;li&gt;each node has a value and a pointer to the next node (or null at the end of the list)&lt;&#x2F;li&gt;
&lt;li&gt;has a head (=start), a tail (=end) and a length&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;singly&amp;quot; because only one connection to another node (the next one)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;setup&quot;&gt;Setup&lt;&#x2F;h2&gt;
&lt;p&gt;So we need two basic entities:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;a single place with a riddle (=&amp;gt; a &lt;code&gt;node&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;the complete treasure hunt (=&amp;gt; the &lt;code&gt;Singly Linked List&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;node&quot;&gt;Node&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;create a file named &lt;code&gt;singly-linked-list.js&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;add this code&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; name of the class
class Node {
  &amp;#x2F;&amp;#x2F; the constructor runs when using the class with `new` (see later)
  constructor(value) {
    &amp;#x2F;&amp;#x2F; set this nodes value property to the instantiation value
    this.value = value;
    &amp;#x2F;&amp;#x2F; set this nodes next property to `null`
    this.next = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This is a JavaScript class. Under the hood it uses a function, but it doesn&#x27;t matter, it&#x27;s all about the concept. We use this object oriented approach, because it is simple to understand.&lt;&#x2F;p&gt;
&lt;p&gt;We have a class and this class acts as a blueprint for a node.&lt;&#x2F;p&gt;
&lt;p&gt;We can instantiate a new instance of this class and save it into a variable:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newNode = new Node(&amp;quot;Empire State Building&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The string &amp;quot;Empire State Building&amp;quot; becomes the &lt;code&gt;value&lt;&#x2F;code&gt; in the constructor, so &lt;code&gt;this.value&lt;&#x2F;code&gt; becomes &lt;code&gt;&amp;quot;Empire State Building&amp;quot;&lt;&#x2F;code&gt;. &lt;code&gt;this.next&lt;&#x2F;code&gt; becomes &lt;code&gt;null&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;We can see this by logging it:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(newNode); &amp;#x2F;&amp;#x2F; Node { value: &amp;#x27;Empire State Building&amp;#x27;, next: null }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can now create as many nodes as we need by using &lt;code&gt;new Node()&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;singly-linked-list&quot;&gt;Singly Linked List&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;add this code to &lt;code&gt;singly-linked-list.js&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; name of the class
class SinglyLinkedList {
  &amp;#x2F;&amp;#x2F; the constructor runs when using the class with `new`
  constructor() {
    &amp;#x2F;&amp;#x2F; set this lists length property to `0`
    this.length = 0;
    &amp;#x2F;&amp;#x2F; set this lists head property to `null`
    this.head = null;
    &amp;#x2F;&amp;#x2F; set this lists tail property to `null`
    this.tail = null;
  }
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Similar to our &lt;code&gt;Node&lt;&#x2F;code&gt;. Every instance of the Singly Linked List gets a &lt;code&gt;length&lt;&#x2F;code&gt;, a &lt;code&gt;head&lt;&#x2F;code&gt; and a &lt;code&gt;tail&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;We can instantiate a new instance of this class and save it into a variable:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const newSinglyLinkedList = new SinglyLinkedList();
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Because all of your three properties are set to default values in the constructor, we don&#x27;t need arguments.&lt;&#x2F;p&gt;
&lt;p&gt;We can see this by logging it:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(newSinglyLinkedList); &amp;#x2F;&amp;#x2F; SinglyLinkedList { length: 0, head: null, tail: null }
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can now create our Singly Linked List by using &lt;code&gt;new SinglyLinkedList()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement how to add a node at the end of the Singly Linked List. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Did you ever use a Singly Linked List in a project? Why?&lt;&#x2F;li&gt;
&lt;li&gt;Did you ever use classes in JavaScript?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>JavaScript Data Structures: Singly Linked List</title>
        <published>2019-11-14T00:00:00+00:00</published>
        <updated>2019-11-14T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-14/" type="text/html"/>
        <id>https://miku86.com/2019-11-14/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;This is a new series about Data Structures in JavaScript.&lt;&#x2F;p&gt;
&lt;p&gt;I will give you some details about the Data Structure and then we implement the Data Structure in JavaScript. The parts will be short, because most people have to familiarize with the logical steps and concepts behind it.&lt;&#x2F;p&gt;
&lt;p&gt;If you aren&#x27;t familiar with Big O Notation, read the article in the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;simple.wikipedia.org&#x2F;wiki&#x2F;Big_O_notation&quot;&gt;Simple Wiki&lt;&#x2F;a&gt;. Don&#x27;t get caught in the details, only try to grasp the concept.&lt;&#x2F;p&gt;
&lt;p&gt;Simple example: If I have a todo list with pen and paper and I want to add a new todo to the end, that&#x27;s &lt;code&gt;O(1)&lt;&#x2F;code&gt;. Why? No matter how long the list actually is, adding a new todo to the end always requires the same amount of work.&lt;&#x2F;p&gt;
&lt;p&gt;Today we start with a simple one: Singly Linked List.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;singly-linked-list&quot;&gt;Singly Linked List&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;simple example in real life: a treasure hunt, where you have a starting point and have to seek places and solve riddles in a particular order; the current place knows about the next place, but the current place doesn&#x27;t know about the previous place&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;what-is-a-singly-linked-list&quot;&gt;What is a Singly Linked List?&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;consists of nodes&lt;&#x2F;li&gt;
&lt;li&gt;each node has a value and a pointer to the next node (or null at the end of the list)&lt;&#x2F;li&gt;
&lt;li&gt;has a head (=start), a tail (=end) and a length&lt;&#x2F;li&gt;
&lt;li&gt;has no index like an Array&lt;&#x2F;li&gt;
&lt;li&gt;&amp;quot;singly&amp;quot; because only one connection to another node (the next one)&lt;&#x2F;li&gt;
&lt;li&gt;access has always to start from the start (&lt;code&gt;O(N)&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;insertion is cheap (&lt;code&gt;O(1)&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;deletion can be cheap (&lt;code&gt;O(1)&lt;&#x2F;code&gt; (head) or &lt;code&gt;O(N)&lt;&#x2F;code&gt; (tail))&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;what-is-an-array&quot;&gt;What is an Array?&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;every element has an index&lt;&#x2F;li&gt;
&lt;li&gt;accessed is cheap (&lt;code&gt;O(1)&lt;&#x2F;code&gt;) (every element has an index)&lt;&#x2F;li&gt;
&lt;li&gt;insert and delete can be expensive (&lt;code&gt;O(N)&lt;&#x2F;code&gt;) (index has to be shifted)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;big-o-of-singly-linked-list&quot;&gt;Big O of Singly Linked List&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Access: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Insert: &lt;code&gt;O(1)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Delete: &lt;code&gt;O(1)&lt;&#x2F;code&gt; (head) or &lt;code&gt;O(N)&lt;&#x2F;code&gt; (tail)&lt;&#x2F;li&gt;
&lt;li&gt;Search: &lt;code&gt;O(N)&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;when-to-use-a-singly-linked-list-instead-of-an-array&quot;&gt;When to use a Singly Linked List instead of an Array?&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;if you insert data often (SLL: &lt;code&gt;O(1)&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;if you delete data at the head often (SLL: &lt;code&gt;O(1)&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;when-not-to-use-a-singly-linked-list-instead-of-an-array&quot;&gt;When NOT to use a Singly Linked List instead of an Array?&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;if you access data often (Array: &lt;code&gt;O(1)&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h3&gt;
&lt;p&gt;We will implement the first part of our Singly Linked List in JavaScript. If you want to be notified, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;subscribe&lt;&#x2F;a&gt; :)&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Example: Imperative vs. Functional</title>
        <published>2019-11-09T00:00:00+00:00</published>
        <updated>2019-11-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-09/" type="text/html"/>
        <id>https://miku86.com/2019-11-09/</id>
        
        <content type="html">&lt;p&gt;Lately, I got a lot of questions about functional programming.&lt;&#x2F;p&gt;
&lt;p&gt;So here&#x27;s a small example about the different approaches.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; list of my friends
const friends = [
  { name: &amp;quot;Erwin&amp;quot;, drinks: [&amp;quot;beer&amp;quot;, &amp;quot;coffee&amp;quot;] },
  { name: &amp;quot;Peter&amp;quot;, drinks: [&amp;quot;beer&amp;quot;] },
  { name: &amp;quot;Heidi&amp;quot;, drinks: [&amp;quot;water&amp;quot;] },
];

&amp;#x2F;&amp;#x2F; what do we want to search?
const itemToSearch = &amp;quot;beer&amp;quot;;

&amp;#x2F;***********************************
 * imperative approach
 *&amp;#x2F;

&amp;#x2F;&amp;#x2F; a place to store the results
let resultImperative = [];

&amp;#x2F;&amp;#x2F; go over every friend
for (friend of friends) {
  &amp;#x2F;&amp;#x2F; check if the person drinks this
  if (friend.drinks.includes(itemToSearch)) {
    &amp;#x2F;&amp;#x2F; add it to the results
    resultImperative.push(friend.name);
  }
}
console.log(resultImperative); &amp;#x2F;&amp;#x2F; [ &amp;#x27;Erwin&amp;#x27;, &amp;#x27;Peter&amp;#x27; ]

&amp;#x2F;***********************************
 * functional approach
 *&amp;#x2F;
const resultFunctional = friends
  &amp;#x2F;&amp;#x2F; check if the person drinks this
  .filter((friend) =&amp;gt; friend.drinks.includes(itemToSearch))
  &amp;#x2F;&amp;#x2F; only give me the name
  .map((friend) =&amp;gt; friend.name);
console.log(resultFunctional); &amp;#x2F;&amp;#x2F; [ &amp;#x27;Erwin&amp;#x27;, &amp;#x27;Peter&amp;#x27; ]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I like the second approach more:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;less complexity,&lt;&#x2F;li&gt;
&lt;li&gt;increased readability&lt;&#x2F;li&gt;
&lt;li&gt;constant level of abstraction&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Chrome Dev Tools</title>
        <published>2019-11-06T00:00:00+00:00</published>
        <updated>2019-11-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-06/" type="text/html"/>
        <id>https://miku86.com/2019-11-06/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;Today we&#x27;ll learn about a tool, which we can use to actually work with the DOM - Chrome and its Dev Tools.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;suggestion&quot;&gt;Suggestion&lt;&#x2F;h2&gt;
&lt;p&gt;Open Chrome or Chromium &lt;strong&gt;now&lt;&#x2F;strong&gt; and try this stuff out. Learning by doing. If you find an error or have a suggestion, I&#x27;d love to read your comment.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;general-shortcuts&quot;&gt;General Shortcuts&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open selected DOM element: &lt;code&gt;Right Click =&amp;gt; Inspect&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Open Last Opened Panel: &lt;code&gt;F12&lt;&#x2F;code&gt; or &lt;code&gt;Ctrl + Shift + I&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Open Elements Panel: &lt;code&gt;Ctrl + Shift + C&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Open Console Panel: &lt;code&gt;Ctrl + Shift + J&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Open&#x2F;close additional Console Panel in any other Panel: &lt;code&gt;Esc&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Open Command Menu (from any Panel): &lt;code&gt;Ctrl + Shift + P&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Open Mobile View (from any Panel): &lt;code&gt;Ctrl + Shift + M&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Open Sensors (from any Panel): &lt;code&gt;Ctrl + Shift + P&lt;&#x2F;code&gt; and type &lt;code&gt;sensors&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Dock to right (from any Panel): &lt;code&gt;Ctrl + Shift + P&lt;&#x2F;code&gt;, type &lt;code&gt;right&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Dock to bottom (from any Panel): &lt;code&gt;Ctrl + Shift + P&lt;&#x2F;code&gt;, type &lt;code&gt;bottom&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Undock to separate window (from any Panel): &lt;code&gt;Ctrl + Shift + P&lt;&#x2F;code&gt;, type &lt;code&gt;separate&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;For Mac, use &lt;code&gt;Command + Option&lt;&#x2F;code&gt; instead of &lt;code&gt;Ctrl + Shift&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developers.google.com&#x2F;web&#x2F;tools&#x2F;chrome-devtools&#x2F;shortcuts&quot;&gt;Source&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h3 id=&quot;elements-panel&quot;&gt;Elements Panel&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;shows the DOM and its Markup and Styles&lt;&#x2F;li&gt;
&lt;li&gt;selected elements get highlighted in the viewport, including margins (orange) and paddings (purple)&lt;&#x2F;li&gt;
&lt;li&gt;change markup temporary by adding&#x2F;deleting&#x2F;editing the HTML nodes&lt;&#x2F;li&gt;
&lt;li&gt;change styles temporary by (un)checking the boxes or adding&#x2F;deleting&#x2F;editing the properties&lt;&#x2F;li&gt;
&lt;li&gt;numbers in the Styles can get changed by using arrows (use &lt;code&gt;Ctrl&lt;&#x2F;code&gt; or &lt;code&gt;Shift&lt;&#x2F;code&gt; additionally and see what will happen)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;console-panel&quot;&gt;Console Panel&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;shows output of code the developer added with &lt;code&gt;console&lt;&#x2F;code&gt;, errors etc.&lt;&#x2F;li&gt;
&lt;li&gt;you can run JavaScript here&lt;&#x2F;li&gt;
&lt;li&gt;you can programmatically access and modify the DOM, e.g. getting all &lt;code&gt;h2&lt;&#x2F;code&gt;s&lt;&#x2F;li&gt;
&lt;li&gt;you can replace &lt;code&gt;document.querySelector()&lt;&#x2F;code&gt; with &lt;code&gt;$()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;you can replace &lt;code&gt;document.querySelectorAll()&lt;&#x2F;code&gt; with &lt;code&gt;$$()&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;if you use a method to find a DOM element, you will see a preview of the result&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;$0&lt;&#x2F;code&gt; gives you the last selected element from the Element Panel&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;sources-panel-awesome-for-debugging&quot;&gt;Sources Panel (awesome for Debugging)&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;shows all the served files from the currently opened page&lt;&#x2F;li&gt;
&lt;li&gt;you can go into a &lt;code&gt;.js&lt;&#x2F;code&gt; file, set a breakpoint and reload the page, the js code will stop&lt;&#x2F;li&gt;
&lt;li&gt;you can hit &lt;code&gt;F9&lt;&#x2F;code&gt; and go step-by-step through the code, seeing the internals of the code&lt;&#x2F;li&gt;
&lt;li&gt;when you click on &lt;code&gt;Snippets&lt;&#x2F;code&gt;, you can write and save custom snippets&lt;&#x2F;li&gt;
&lt;li&gt;you can run a script with &lt;code&gt;Ctrl + Enter&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;network-panel&quot;&gt;Network Panel&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;shows the network activity between client (our browser) and the server(s) (where we get our data from)&lt;&#x2F;li&gt;
&lt;li&gt;shows the load time, the size of sent data, the amount of requests etc.&lt;&#x2F;li&gt;
&lt;li&gt;we can filter the type of resources&lt;&#x2F;li&gt;
&lt;li&gt;we can see our requests to the server(s) and their responses&lt;&#x2F;li&gt;
&lt;li&gt;red font color means something didn&#x27;t (intentionally) work, e.g. adblocker blocked a file&lt;&#x2F;li&gt;
&lt;li&gt;you can simulate different internet speeds to see which resources slow down your page&lt;&#x2F;li&gt;
&lt;li&gt;you can search for specific files with &lt;code&gt;Ctrl + F&lt;&#x2F;code&gt;, even with Regex&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;application-panel&quot;&gt;Application Panel&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;shows manifest and service workers of the page&lt;&#x2F;li&gt;
&lt;li&gt;shows storage, e.g. Local Storage, Session Storage, IndexedDB, Cookies of the page&lt;&#x2F;li&gt;
&lt;li&gt;shows cache, e.g. of the service worker&lt;&#x2F;li&gt;
&lt;li&gt;shows background services, e.g. sync, notifications, push messages&lt;&#x2F;li&gt;
&lt;li&gt;you can delete all your stored data from a page here&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;audit-panel&quot;&gt;Audit Panel&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;you can get a audit of you page here (performance, accessibility etc.)&lt;&#x2F;li&gt;
&lt;li&gt;doesn&#x27;t work on a local page&lt;&#x2F;li&gt;
&lt;li&gt;gives feedback on how to optimize your page&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;sensors&quot;&gt;Sensors&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;you can change your location, e.g. if you want to check if your webpage&#x27;s geo location is working properly&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>HTML DOM Manipulation with JavaScript</title>
        <published>2019-11-05T00:00:00+00:00</published>
        <updated>2019-11-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-11-05/" type="text/html"/>
        <id>https://miku86.com/2019-11-05/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;The DOM (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Document_Object_Model&quot;&gt;Document Object Model&lt;&#x2F;a&gt;) is an interface, where you can access and manipulate content, structure and style of a website.&lt;&#x2F;p&gt;
&lt;p&gt;We will have a look at the following topics:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What is the DOM?&lt;&#x2F;li&gt;
&lt;li&gt;How can we manipulate it?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;what-is-the-dom&quot;&gt;What is the DOM?&lt;&#x2F;h2&gt;
&lt;p&gt;When we open a HTML file in our browser, the DOM gets created by the browser, so the DOM is the representation of a HTML document.&lt;&#x2F;p&gt;
&lt;p&gt;HTML elements, e.g. &lt;code&gt;&amp;lt;body&amp;gt;&amp;lt;&#x2F;body&amp;gt;&lt;&#x2F;code&gt;, &lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;&#x2F;p&amp;gt;&lt;&#x2F;code&gt;, become so-called nodes. Nodes have relationships to each other and are structured as a tree.&lt;&#x2F;p&gt;
&lt;p&gt;The root of the DOM is called &lt;code&gt;document&lt;&#x2F;code&gt;.
By using JavaScript, the DOM can be accessed and manipulated.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;accessing-a-node-html-element&quot;&gt;Accessing a Node &#x2F; HTML element&lt;&#x2F;h2&gt;
&lt;p&gt;There are various way to access a single node.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;queryselector&quot;&gt;&lt;code&gt;querySelector&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;querySelector&lt;&#x2F;code&gt; is a method to input a complete query and get the first occurrence back.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; access the body tag
document.querySelector(&amp;quot;body&amp;quot;);

&amp;#x2F;&amp;#x2F; access the &amp;quot;button&amp;quot;-class
document.querySelector(&amp;quot;.button&amp;quot;);

&amp;#x2F;&amp;#x2F; access the &amp;quot;footer&amp;quot;-id
document.querySelector(&amp;quot;#footer&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As we can see, we can access an element by tag(&lt;code&gt;body&lt;&#x2F;code&gt;), by class(&lt;code&gt;.button&lt;&#x2F;code&gt;) or by id(&lt;code&gt;#footer&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;h3 id=&quot;queryselectorall&quot;&gt;&lt;code&gt;querySelectorAll&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;querySelectorAll&lt;&#x2F;code&gt; is a method to input a complete query and get all occurrences back.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; access the &amp;quot;button&amp;quot;-class
document.querySelectorAll(&amp;quot;.button&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;getelementbyid&quot;&gt;&lt;code&gt;getElementById&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;getElementById&lt;&#x2F;code&gt; is a method to get a single element with a specific id.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;document.getElementById(&amp;quot;header&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We get the element that has the id &lt;code&gt;header&lt;&#x2F;code&gt;.
We don&#x27;t need &lt;code&gt;#&lt;&#x2F;code&gt; like when using &lt;code&gt;querySelector&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;getelementsbyclassname&quot;&gt;&lt;code&gt;getElementsByClassName&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;getElementsByClassName&lt;&#x2F;code&gt; is a method to get all elements with a specific class.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;document.getElementsByClassName(&amp;quot;button&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We get the elements that has the class &lt;code&gt;button&lt;&#x2F;code&gt;.
We don&#x27;t need &lt;code&gt;.&lt;&#x2F;code&gt; like when using &lt;code&gt;querySelector&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Like we can see in the method name, &lt;code&gt;Elements&lt;&#x2F;code&gt; is plural, therefore we get a collection of HTML elements back, not a single element, even if it is empty.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;getelementsbytagname&quot;&gt;&lt;code&gt;getElementsByTagName&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;getElementsByTagName&lt;&#x2F;code&gt; is a method to get all elements with a specific HTML tag.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;document.getElementsByTagName(&amp;quot;p&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We get the elements that has the HTML tag &lt;code&gt;p&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Like we can see in the method name, &lt;code&gt;Elements&lt;&#x2F;code&gt; is plural, therefore we get a collection of HTML elements back, not a single element, even if it is empty.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;what-do-i-use&quot;&gt;What do I use?&lt;&#x2F;h3&gt;
&lt;p&gt;I use &lt;code&gt;querySelector&lt;&#x2F;code&gt; and &lt;code&gt;querySelectorAll&lt;&#x2F;code&gt;, because both can be used with tag, class and id.
I don&#x27;t want to change multiple lines when I change an &lt;code&gt;id&lt;&#x2F;code&gt; into a &lt;code&gt;class&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;There is a lot of legacy and transpiled code, therefore you should know how to use all the other methods, too.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;more-complex-queries&quot;&gt;More complex queries&lt;&#x2F;h3&gt;
&lt;p&gt;Sometimes you have to find more complex stuff&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; a tag with a class
document.querySelector(&amp;quot;body.main&amp;quot;);
&amp;#x2F;&amp;#x2F; &amp;lt;body class=&amp;quot;main&amp;quot;&amp;gt;

&amp;#x2F;&amp;#x2F; a class as a child in a tag
document.querySelector(&amp;quot;body &amp;gt; .text&amp;quot;);
&amp;#x2F;&amp;#x2F; &amp;lt;body&amp;gt;&amp;lt;p class=&amp;quot;text&amp;quot;&amp;gt;...&amp;lt;&amp;#x2F;p&amp;gt;&amp;lt;&amp;#x2F;body&amp;gt;

&amp;#x2F;&amp;#x2F; a class anywhere in a tag
document.querySelector(&amp;quot;body .text&amp;quot;);
&amp;#x2F;&amp;#x2F; &amp;lt;body&amp;gt;&amp;lt;section&amp;gt;&amp;lt;p class=&amp;quot;text&amp;quot;&amp;gt;...&amp;lt;&amp;#x2F;p&amp;gt;&amp;lt;&amp;#x2F;section&amp;gt;&amp;lt;&amp;#x2F;body&amp;gt;

&amp;#x2F;&amp;#x2F; a parent
document.querySelector(&amp;quot;body&amp;quot;).parentNode;

&amp;#x2F;&amp;#x2F; all children
document.querySelector(&amp;quot;body&amp;quot;).childNodes;

&amp;#x2F;&amp;#x2F; first child
document.querySelector(&amp;quot;body&amp;quot;).firstChild;

&amp;#x2F;&amp;#x2F; last child
document.querySelector(&amp;quot;body&amp;quot;).lastChild;

&amp;#x2F;&amp;#x2F; previous sibling
document.querySelector(&amp;quot;body&amp;quot;).previousSibling;

&amp;#x2F;&amp;#x2F; next sibling
document.querySelector(&amp;quot;body&amp;quot;).nextSibling;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;manipulating-elements-in-the-dom&quot;&gt;Manipulating elements in the DOM&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; change text content of a node
document.querySelector(&amp;quot;.text&amp;quot;).textContent = &amp;quot;Hello&amp;quot;;

&amp;#x2F;&amp;#x2F; change HTML content
document.querySelector(&amp;quot;.text&amp;quot;).innerHTML = &amp;quot;&amp;lt;p&amp;gt;Hello&amp;lt;&amp;#x2F;p&amp;gt;&amp;quot;;

&amp;#x2F;&amp;#x2F; change source of an image
document.querySelector(&amp;quot;.logo&amp;quot;).src = &amp;quot;lion.jpeg&amp;quot;;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;creating-new-elements-in-the-dom&quot;&gt;Creating new elements in the DOM&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; create a new element and store it into a variable
const newParagraph = document.createElement(&amp;quot;p&amp;quot;);

&amp;#x2F;&amp;#x2F; add text to the newly created paragraph
newParagraph.textContent = &amp;quot;Hello&amp;quot;;

&amp;#x2F;&amp;#x2F; find container where the new paragraph should live in
const container = document.querySelector(&amp;quot;body&amp;quot;);

&amp;#x2F;&amp;#x2F; add new paragraph to container
container.appendChild(newParagraph);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;adding-an-event-listener-to-the-dom&quot;&gt;Adding an Event Listener to the DOM&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;html&quot; class=&quot;language-html &quot;&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&amp;lt;!-- a simple button --&amp;gt;
&amp;lt;button class=&amp;quot;my-cool-button&amp;quot;&amp;gt;Click Me&amp;lt;&amp;#x2F;button&amp;gt;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; find the button in the DOM by using the class
const myButton = document.querySelector(&amp;quot;.my-cool-button&amp;quot;);

&amp;#x2F;&amp;#x2F; add a listener to the button, that waits for a &amp;quot;click&amp;quot; event,
&amp;#x2F;&amp;#x2F; then run the following function
myButton.addEventListener(&amp;quot;click&amp;quot;, function () {
  alert(&amp;quot;Hi&amp;quot;);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;outro&quot;&gt;Outro&lt;&#x2F;h2&gt;
&lt;p&gt;These are just a few of the ways to work with the DOM to give you a small primer.&lt;&#x2F;p&gt;
&lt;p&gt;If you want to dive deeper into the topic, read this &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;bit.ly&#x2F;dev-dom&quot;&gt;free book&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>VSCode: Transform text to lowercase&#x2F;uppercase&#x2F;titlecase</title>
        <published>2019-10-29T00:00:00+00:00</published>
        <updated>2019-10-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-10-29/" type="text/html"/>
        <id>https://miku86.com/2019-10-29/</id>
        
        <content type="html">&lt;p&gt;VSCode has an built-in function to lowercase, uppercase and titlecase selected text.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Select the text to transform. Use &lt;code&gt;Ctrl + L&lt;&#x2F;code&gt; to selected the whole line&lt;&#x2F;li&gt;
&lt;li&gt;Open &lt;code&gt;Show all commands&lt;&#x2F;code&gt;. Linux and Windows: &lt;code&gt;Ctrl + Shift + P&lt;&#x2F;code&gt;, Mac: &lt;code&gt;⇧⌘P&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Type in the command, e.g. &lt;code&gt;lower&lt;&#x2F;code&gt;, &lt;code&gt;upper&lt;&#x2F;code&gt;, &lt;code&gt;title&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Wait for auto-complete (like in the animation)&lt;&#x2F;li&gt;
&lt;li&gt;Hit &lt;code&gt;Enter&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Bash: Rename specific files in a folder</title>
        <published>2019-10-22T00:00:00+00:00</published>
        <updated>2019-10-22T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-10-22/" type="text/html"/>
        <id>https://miku86.com/2019-10-22/</id>
        
        <content type="html">&lt;p&gt;Recently I&#x27;ve built a script to download all my articles from dev.to into markdown files.&lt;&#x2F;p&gt;
&lt;p&gt;I used the timestamp and the name of the article.&lt;&#x2F;p&gt;
&lt;p&gt;This is working, but there is one annoying thing: every post has a date in its file name and its frontmatter.&lt;&#x2F;p&gt;
&lt;p&gt;That leads to:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Increased complexity: Would have to change the date in both places if I would want to change the date.&lt;&#x2F;li&gt;
&lt;li&gt;What would be the source of truth in case of two different dates?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;let-s-tackle-this-problem&quot;&gt;Let&#x27;s tackle this problem&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;# loop over every file with `md` extension, assign it to `file`
for file in *.md
do
  # rename (by variable expansion starting from position 11)
  mv &amp;quot;$file&amp;quot; &amp;quot;${file:11}&amp;quot;
done
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;linuxcommand.org&#x2F;lc3_man_pages&#x2F;forh.html&quot;&gt;for man page&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;mv&quot;&gt;mv man page&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;www.tldp.org&#x2F;LDP&#x2F;abs&#x2F;html&#x2F;parameter-substitution.html#EXPREPL1&quot;&gt;Variable Expansion&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Learn In Public</title>
        <published>2019-10-21T00:00:00+00:00</published>
        <updated>2019-10-21T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-10-21/" type="text/html"/>
        <id>https://miku86.com/2019-10-21/</id>
        
        <content type="html">&lt;p&gt;I &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.swyx.io&#x2F;writing&#x2F;learn-in-public&#x2F;&quot;&gt;recently read&lt;&#x2F;a&gt; about the concept of &amp;quot;Learn In Public&amp;quot;. I adopted &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.taniarascia.com&#x2F;learn&#x2F;&quot;&gt;this list&lt;&#x2F;a&gt; and modified it to fit my needs. &lt;a href=&quot;&#x2F;pages&#x2F;learn-in-public&quot;&gt;This is the result&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;key-takeaways&quot;&gt;Key Takeaways&lt;&#x2F;h3&gt;
&lt;blockquote&gt;
&lt;p&gt;You already know that you will never be done learning. But most people &amp;quot;learn in private&amp;quot;, and lurk. They consume content without creating any themselves.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Absolutely true. I think this is one of the most dangerous things you can do. Because it gives you the feeling, that you actually achieved something.&lt;&#x2F;p&gt;
&lt;p&gt;Consuming isn&#x27;t an achievement. Everyone can consume. We live in a consume-driven world. A dangerous place to be. &amp;quot;Man, I was so busy. I watched 2h of tutorials, then I read this blog, then I read stuff on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;twitter.com&#x2F;miku86com&quot;&gt;Twitter&lt;&#x2F;a&gt;.&amp;quot;. And suddenly, 2 months are gone &amp;amp; you stretched yourself for 2h in this time period while copying code from YouTube.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t get me wrong, better done than perfect. 2h &amp;gt; 0h.&lt;&#x2F;p&gt;
&lt;p&gt;BUT: You need to learn the skill of going out alone.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;blockquote&gt;
&lt;p&gt;Write blogs and tutorials and cheatsheets. Speak at meetups and conferences. Ask and answer things on Stackoverflow or Reddit. Make Youtube videos or Twitch streams. Start a newsletter. Whatever your thing is, make the thing you wish you had found when you were learning. Don&#x27;t stop there. Enjoyed a coding video? Reach out to the speaker&#x2F;instructor and thank them, and ask questions. Make PR&#x27;s to libraries you use. Make your own libraries no one will ever use. Clone stuff you like. Teach workshops. Go to conferences and summarize what you learned. There&#x27;s always one level deeper. But at every step of the way: Document what you did and the problems you solved.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Leave your shelter, test the market. Get a lot of feedback. See where you can improve. Most of the time it isn&#x27;t your code. Ask for feedback.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;blockquote&gt;
&lt;p&gt;If you feel uncomfortable, or like an impostor, good. You&#x27;re pushing yourself. Don&#x27;t assume you know everything, but try your best anyway, and let the internet correct you when you are inevitably wrong. Wear your noobyness on your sleeve. People think you suck? Good. You agree. Ask them to explain, in detail, why you suck. You want to just feel good or you want to be good? No objections, no hurt feelings.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I think most of the time imposter syndrom comes from all these edited YouTube tutorials, where one guy codes some tool and you are like &amp;quot;That was fast, I need 10x the time.&amp;quot;. This is free coaching. Other people pay a lot of money for coaching.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;blockquote&gt;
&lt;p&gt;At some point you&#x27;ll get some support behind you. People notice genuine learners. They&#x27;ll want to help you. Don&#x27;t tell them, but they just became your mentors. This is very important: Pick up what they put down. Think of them as offering up quests for you to complete. When they say &amp;quot;Anyone willing to help with ___?&amp;quot; you&#x27;re that kid in the first row with your hand already raised. These are senior engineers, some of the most in-demand people in tech. They&#x27;ll spend time with you, 1 on 1, if you help them out (p.s. and there&#x27;s always something they want help on). You can&#x27;t pay for this stuff. They&#x27;ll teach you for free. Most people don&#x27;t see what&#x27;s right in front of them. But not you. Because you learn in public. By teaching you they teach many. You amplify them. You have one thing they don&#x27;t: a beginner&#x27;s mind. You see how this works?&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Luckily, I was&#x2F;am this kind of person my whole life. My ego is very small &amp;amp; don&#x27;t feel dumb when asking questions. I genuinely love to ask questions. Feedback is a great opportunity. Doing stuff is a great opportunity.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;blockquote&gt;
&lt;p&gt;At some point people will start asking you for help because of all the stuff you put out. 80% of developers are &amp;quot;dark&amp;quot;, they don&#x27;t write or speak or participate in public tech discourse. But you do. You must be an expert, right? Don&#x27;t tell them you aren&#x27;t. Answer best as you can, and when you&#x27;re stuck or wrong pass it up to your mentors.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I don&#x27;t participate in public tech discourse, because I don&#x27;t care. I write&#x2F;develop stuff. I respond to every comment and e-mail I get.&lt;&#x2F;p&gt;
&lt;p&gt;That&#x27;s it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a href=&quot;&#x2F;pages&#x2F;learn-in-public&quot;&gt;Learn In Public&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>30 Day Challenge: 30 Posts in 30 Days</title>
        <published>2019-10-20T00:00:00+00:00</published>
        <updated>2019-10-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-10-20/" type="text/html"/>
        <id>https://miku86.com/2019-10-20/</id>
        
        <content type="html">&lt;p&gt;My &lt;strong&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;dev.to&#x2F;miku86&#x2F;30-day-challenge-finish-line-3imn&quot;&gt;first 30 Day Challenge&lt;&#x2F;a&gt;&lt;&#x2F;strong&gt; was a huge success &amp;amp; an awesome experience.&lt;&#x2F;p&gt;
&lt;p&gt;Therefore, I announce Round #2.
This time &amp;quot;&lt;strong&gt;30 Day Challenge: 30 Posts in 30 Days.&lt;&#x2F;strong&gt;&amp;quot;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;my-why-changed-a-little-bit&quot;&gt;My &lt;strong&gt;Why&lt;&#x2F;strong&gt; changed a little bit&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;I want to strengthen my &lt;strong&gt;&amp;quot;Finding a solution, no matter what&amp;quot;&lt;&#x2F;strong&gt;-skill (I will go on vacation for 5 days &amp;amp; I&#x27;ll post on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;miku86.com&lt;&#x2F;a&gt; too.&lt;&#x2F;li&gt;
&lt;li&gt;I want to strengthen my &lt;strong&gt;shipping&lt;&#x2F;strong&gt; skills. I am very good at starting small hobby projects, but then I am afraid that nobody will be interested in them &amp;amp; finally I don&#x27;t ship them.&lt;&#x2F;li&gt;
&lt;li&gt;I want to &lt;strong&gt;tackle my fear&lt;&#x2F;strong&gt; of &amp;quot;Nobody cares.&amp;quot;.&lt;&#x2F;li&gt;
&lt;li&gt;I want to strengthen my &lt;strong&gt;writing skills&lt;&#x2F;strong&gt;. (=&amp;gt; simpler to understand)&lt;&#x2F;li&gt;
&lt;li&gt;I want to benefit from &lt;strong&gt;social accountability&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;I want to &lt;strong&gt;share my knowledge&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;rules&quot;&gt;Rules&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;deadline: 19.11.2019, 23:59 UTC +1&lt;&#x2F;li&gt;
&lt;li&gt;no copy of an old post&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;What are your experiences with these kind of challenges?&lt;&#x2F;li&gt;
&lt;li&gt;Love to hear your feedback, tips, suggestions!&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;strong&gt;PS:&lt;&#x2F;strong&gt; If you want to reach out to me or have a question (I love beginners&#x27; questions, &lt;strong&gt;beginners are welcome!&lt;&#x2F;strong&gt;), &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;&quot;&gt;send me a message&lt;&#x2F;a&gt;. &lt;strong&gt;100%&lt;&#x2F;strong&gt; response rate!&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Best Resources To Start Into Learning Web Development</title>
        <published>2019-10-07T00:00:00+00:00</published>
        <updated>2019-10-07T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-10-07/" type="text/html"/>
        <id>https://miku86.com/2019-10-07/</id>
        
        <content type="html">&lt;p&gt;In my JavaScript workshops I get constantly asked,
which learning resources I can recommend.&lt;&#x2F;p&gt;
&lt;p&gt;Because this is an important &amp;amp; interesting question,
I will give you my opinion on this.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;html-css&quot;&gt;HTML + CSS:&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Read: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-mdn-html&quot;&gt;MDN: HTML&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Read: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-mdn-css&quot;&gt;MDN: CSS&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Read: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-wd4m&quot;&gt;Web Design in 4 minutes&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;MDN is a great resource to get into learning.
Sometimes they use a lot of tech speech,
but later on you want to read a lot of documentations,
therefore you want to familiarize yourself with tech speech.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;javascript-beginner&quot;&gt;JAVASCRIPT: Beginner&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Read: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-js14m&quot;&gt;JavaScript in 14 minutes&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Read: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-mdn-js&quot;&gt;MDN: JavaScript&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Watch: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-pjs&quot;&gt;Practical JavaScript&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Watch: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-mjsbc&quot;&gt;The Modern JavaScript Bootcamp (2019)&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I would do all the stuff in exactly that order,
because first you do some small practical stuff (JS in 14min),
then you learn the theory behind it (MDN JS),
then you build a lot of practical stuff (PracticalJS)
and finally you do all over again in a great course (JS Bootcamp).&lt;&#x2F;p&gt;
&lt;h3 id=&quot;javascript-advanced&quot;&gt;JAVASCRIPT: Advanced&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Watch: General: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-jsadsmc&quot;&gt;JavaScript Algorithms and Data Structures Masterclass&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Read: General: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-ydkjs&quot;&gt;You don&#x27;t know JS&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Watch: Frontend: React: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-bgr&quot;&gt;The Beginner&#x27;s Guide to React&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Watch: Frontend: React: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-crdc&quot;&gt;The Complete React Developer Course&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Watch: Backend: NodeJS: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-cndc&quot;&gt;The Complete Node.js Developer Course&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;This is my prefered order, but I totally understand that some people don&#x27;t get motivated by the Algorithms &amp;amp; Data Structures stuff.
To my younger self: Learn the Algorithms &amp;amp; Data Structures first. It will save you a lot of times afterwards.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;web-dev-all-in-one&quot;&gt;WEB DEV: All in one&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Watch: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;bit.ly&#x2F;dev-wdbccs&quot;&gt;The Web Developer BootCamp by Colt Steele&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;If you want to do some comprehensive course and not 10 different ones, I would go with this one.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>30 Day Challenge: Finish Line</title>
        <published>2019-09-19T00:00:00+00:00</published>
        <updated>2019-09-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-19/" type="text/html"/>
        <id>https://miku86.com/2019-09-19/</id>
        
        <content type="html">&lt;p&gt;30 Days ago, I started my &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;30-day-challenge-write-one-post-per-day-3jpm&quot;&gt;30 Day Challenge: Write one Post per Day&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;I wrote 29 post.
I failed one day.
I went from ~1.000 followers to &lt;strong&gt;2.972&lt;&#x2F;strong&gt;. (I only added links to old posts, so no active marketing.)&lt;&#x2F;p&gt;
&lt;p&gt;I want to give a small feedback about my learnings,
I will use the content of my intro post for it.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;I want to strengthen my publishing habits
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This worked.
I time-blocked one hour to write and I knew every day, that I had to deliver. Next time, I would make a longer list of topics to write about.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;I want to tackle my fear of publishing
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Most of the time I had thoughts like &amp;quot;Ouh, this is some basic stuff, every one can read about it in the docs, no one will care.&amp;quot;.
But it went better than expected.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;I want to share my knowledge
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Looking at the views and reactions, I can see a clear difference between my series about &lt;code&gt;NodeJS&lt;&#x2F;code&gt; and &lt;code&gt;PostgreSQL&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The more followers I had, the more views and reactions I got.
But this was only true in a series.
So I think, that &lt;code&gt;NodeJS&lt;&#x2F;code&gt; is more interesting than &lt;code&gt;PostgreSQL&lt;&#x2F;code&gt;, or my posts weren&#x27;t that interesting.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;code&gt;1000*x^29=2972&lt;&#x2F;code&gt; =&amp;gt; &lt;code&gt;x≈1.0383&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So 1 post got me an increase of 3.8% in followers.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;I want to strengthen my writing skills
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This was okay. Most of the time half of the blocked time went into reading about the proper english translation. My english writing skills aren&#x27;t that good, my german one&#x27;s are really good, so I got stressed all the time, because my english reads like 5th grade english.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;I want to benefit from social accountability
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The thougth that someone is waiting for my post definitely helped me.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h3&gt;
&lt;p&gt;This was a great experience and I am really happy &amp;amp; proud.
I will start working at a new software project, afterwards I will start a new writing challenge.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS &amp; PostgreSQL: ORM Overview</title>
        <published>2019-09-14T00:00:00+00:00</published>
        <updated>2019-09-14T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-14/" type="text/html"/>
        <id>https://miku86.com/2019-09-14/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;In the last two parts, we learned how to connect a database to a server:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-postgresql-how-to-connect-our-database-to-our-simple-express-server-without-an-orm-10o0&quot;&gt;without ORM&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-postgresql-how-to-connect-our-database-to-our-simple-express-server-with-an-orm-gcm&quot;&gt;with ORM&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;orm-object-relational-mapper&quot;&gt;ORM (Object-Relational-Mapper)&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;what-does-an-orm-do&quot;&gt;What does an ORM do?&lt;&#x2F;h3&gt;
&lt;p&gt;In short, an ORM is a layer between the server and the database.
The server talks with the ORM and the ORM talks to the database.
The ORM creates objects, that map to the relational data.
It handles your queries, so you don&#x27;t have to write native SQL, you can query the database with your application language.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;list-of-orms&quot;&gt;List of ORMs:&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;sequelize&quot;&gt;sequelize&lt;&#x2F;a&gt;: Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;typeorm&quot;&gt;TypeORM&lt;&#x2F;a&gt;: Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Oracle, sql.js, CockroachDB&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;objection&quot;&gt;objection&lt;&#x2F;a&gt;: Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Oracle, Amazon Redshift&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmtrends.com&#x2F;objection-vs-sequelize-vs-typeorm&quot;&gt;Comparison on npmtrends&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If you use &lt;code&gt;MongoDB&lt;&#x2F;code&gt;, you can use an ODM, e.g. &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;mongoose&quot;&gt;&lt;code&gt;mongoose&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;pros&quot;&gt;Pros&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;you don&#x27;t have to learn&#x2F;know&#x2F;write SQL, because the ORM handles it&lt;&#x2F;li&gt;
&lt;li&gt;it will be easier to change your database dialect&lt;&#x2F;li&gt;
&lt;li&gt;your application is less vulnerable to SQL injections&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;cons&quot;&gt;Cons&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;you have to learn the ORM&lt;&#x2F;li&gt;
&lt;li&gt;one additional layer of abstraction decreases the speed (theoretically)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Object-relational_mapping&quot;&gt;Wiki: ORM&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;sequelize&quot;&gt;sequelize&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;typeorm&quot;&gt;TypeORM&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;objection&quot;&gt;objection&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you use an ORM&#x2F;ODM (e.g. Mongoose)? Which one? Why?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS &amp; PostgreSQL: How To Connect A Database To An Express Server (with ORM)</title>
        <published>2019-09-13T00:00:00+00:00</published>
        <updated>2019-09-13T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-13/" type="text/html"/>
        <id>https://miku86.com/2019-09-13/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;We learned:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-what-is-it-how-to-install-it-16hk&quot;&gt;how to do stuff with PostgreSQL&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-create-a-simple-server-using-express-1n9d&quot;&gt;how to create a server with express&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-postgresql-how-to-connect-a-database-to-an-express-server-no-orm-10o0&quot;&gt;how to connect express and PostgreSQL with pg&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Now we want to learn how to connect our PostgreSQL database with our express server with &lt;code&gt;sequelize&lt;&#x2F;code&gt; as &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;q&#x2F;1279613&quot;&gt;ORM&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-a-project-folder-do-npm-init-install-all-needed-packages&quot;&gt;Create A Project Folder, do &lt;code&gt;npm init&lt;&#x2F;code&gt;, install all needed packages&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;mkdir node-postgres-sequelize
cd node-postgres-sequelize
npm init
npm i express sequelize pg pg-hstore
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We can see that &lt;code&gt;sequelize&lt;&#x2F;code&gt; needs &lt;code&gt;pg&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-index-js-and-setup-a-small-server&quot;&gt;Create &lt;code&gt;index.js&lt;&#x2F;code&gt; and setup a small server&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const express = require(&amp;quot;express&amp;quot;);
const app = express();
const PORT = 8080;

app.get(&amp;quot;&amp;#x2F;&amp;quot;, (req, res) =&amp;gt; {
  res.send({ message: &amp;quot;endpoint working&amp;quot; });
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Test your server with &lt;code&gt;node index.js&lt;&#x2F;code&gt;,
it should run at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;localhost:8080&quot;&gt;localhost:8080&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-a-local-database-table-entry&quot;&gt;Create a local database, table &amp;amp; entry&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;sudo -iu postgres
createdb -O postgres node-postgres-sequelize;
psql -d node-postgres-sequelize
\conninfo
CREATE TABLE users(id SERIAL PRIMARY KEY, nickname TEXT NOT NULL);
INSERT INTO users(nickname) VALUES (&amp;#x27;miku86&amp;#x27;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Test your database with &lt;code&gt;SELECT * FROM users;&lt;&#x2F;code&gt;,
there should be &lt;code&gt;1 row&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-database-js-with-only-the-database-stuff&quot;&gt;Create &lt;code&gt;database.js&lt;&#x2F;code&gt; with only the database stuff&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const Sequelize = require(&amp;quot;sequelize&amp;quot;);
&amp;#x2F;&amp;#x2F; your credentials
DATABASE_URL =
  &amp;quot;postgres:&amp;#x2F;&amp;#x2F;[db-user]:[password]@127.0.0.1:5432&amp;#x2F;node-postgres-sequelize&amp;quot;;

const database = new Sequelize(DATABASE_URL);

module.exports = database;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: This implementation is very simple and not for production. You should never move your credentials into this file, you should use something like &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;dotenv&quot;&gt;&lt;code&gt;dotenv&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. But for the sake of simplicity, I make this example as simple as possible.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-user-js-with-one-method-to-read-all-database-rows&quot;&gt;Create &lt;code&gt;User.js&lt;&#x2F;code&gt; with one method to read all database rows&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const Sequelize = require(&amp;quot;sequelize&amp;quot;);
const database = require(&amp;quot;.&amp;#x2F;database&amp;quot;);

const User = database.define(
  &amp;quot;users&amp;quot;,
  {
    nickname: {
      type: Sequelize.TEXT,
    },
  },
  { timestamps: false }
);

User.readAll = async (req, res) =&amp;gt; {
  try {
    const users = await User.findAll();
    return res.send({ users });
  } catch (error) {
    return res.send(error);
  }
};

module.exports = User;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We separate the &lt;code&gt;User&lt;&#x2F;code&gt; model and its &lt;code&gt;readAll()&lt;&#x2F;code&gt; function to make things more obvious. We don&#x27;t have to write the SQL query (e.g. &lt;code&gt;SELECT * FROM users&lt;&#x2F;code&gt;), we can use the &lt;code&gt;sequelize&lt;&#x2F;code&gt;&#x27;s abstraction of it, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sequelize.org&#x2F;master&#x2F;manual&#x2F;querying.html&quot;&gt;&lt;code&gt;findAll()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;. We don&#x27;t care how &lt;code&gt;sequelize&lt;&#x2F;code&gt; is doing this.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;update-index-js-with-a-new-route&quot;&gt;Update &lt;code&gt;index.js&lt;&#x2F;code&gt; with a new route&lt;&#x2F;h2&gt;
&lt;p&gt;We now have to add the &lt;code&gt;users&lt;&#x2F;code&gt; endpoint to &lt;code&gt;index.js&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const express = require(&amp;quot;express&amp;quot;);
&amp;#x2F;&amp;#x2F; new: import User
const User = require(&amp;quot;.&amp;#x2F;User&amp;quot;);
const app = express();
const PORT = 8080;

app.get(&amp;quot;&amp;#x2F;&amp;quot;, (req, res) =&amp;gt; {
  res.send({ message: &amp;quot;endpoint working&amp;quot; });
});

&amp;#x2F;&amp;#x2F; new: route to users, that runs readAll()
app.get(&amp;quot;&amp;#x2F;users&amp;quot;, User.readAll);

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The exact some file like in the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-postgresql-how-to-connect-our-database-to-our-simple-express-server-without-an-orm-10o0&quot;&gt;tutorial without &lt;code&gt;sequelize&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Test your server with &lt;code&gt;node index.js&lt;&#x2F;code&gt;,
it should run at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;localhost:8080&#x2F;users&quot;&gt;localhost:8080&#x2F;users&lt;&#x2F;a&gt; and show all (= 1) rows from the PostgreSQL database.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h2&gt;
&lt;p&gt;In then end, we did these steps:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;created an express server&lt;&#x2F;li&gt;
&lt;li&gt;created a database with one table and content&lt;&#x2F;li&gt;
&lt;li&gt;created a method to read the content&lt;&#x2F;li&gt;
&lt;li&gt;added a route that runs this method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;To setup additional database queries, we only have to:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;add a new method in &lt;code&gt;User.js&lt;&#x2F;code&gt; with a new &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sequelize.readthedocs.io&#x2F;en&#x2F;latest&#x2F;api&#x2F;model&#x2F;&quot;&gt;&lt;code&gt;sequelize&lt;&#x2F;code&gt; method&lt;&#x2F;a&gt; (&lt;code&gt;create()&lt;&#x2F;code&gt;, &lt;code&gt;destroy()&lt;&#x2F;code&gt; etc.)&lt;&#x2F;li&gt;
&lt;li&gt;add a new route in &lt;code&gt;index.js&lt;&#x2F;code&gt; that runs the new method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We created a connection between server and database &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-postgresql-how-to-connect-our-database-to-our-simple-express-server-without-an-orm-10o0&quot;&gt;without ORM (&lt;code&gt;pg&lt;&#x2F;code&gt;)&lt;&#x2F;a&gt; and with ORM(&lt;code&gt;sequelize&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;p&gt;In the next part, we will take a closer look at the pros and cons of both methods.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;&quot;&gt;Express Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;sequelize&quot;&gt;sequelize at npm&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sequelize.org&#x2F;master&#x2F;&quot;&gt;sequelize docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS &amp; PostgreSQL: How To Connect A Database To An Express Server (no ORM)</title>
        <published>2019-09-12T00:00:00+00:00</published>
        <updated>2019-09-12T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-12/" type="text/html"/>
        <id>https://miku86.com/2019-09-12/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;We learned:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-what-is-it-how-to-install-it-16hk&quot;&gt;how to do stuff with PostgreSQL&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-create-a-simple-server-using-express-1n9d&quot;&gt;how to create a server with express&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Now we want to learn how to connect our PostgreSQL database with our express server with &lt;code&gt;pg&lt;&#x2F;code&gt; and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;q&#x2F;1279613&quot;&gt;no ORM&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-a-project-folder-do-npm-init-install-express-pg&quot;&gt;Create A Project Folder, do &lt;code&gt;npm init&lt;&#x2F;code&gt;, install express &amp;amp; pg&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;mkdir node-postgres-pg
cd node-postgres-pg
npm init
npm i express pg
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-index-js-and-setup-a-small-server&quot;&gt;Create &lt;code&gt;index.js&lt;&#x2F;code&gt; and setup a small server&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const express = require(&amp;quot;express&amp;quot;);
const app = express();
const PORT = 8080;

app.get(&amp;quot;&amp;#x2F;&amp;quot;, (req, res) =&amp;gt; {
  res.send({ message: &amp;quot;endpoint working&amp;quot; });
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Test your server with &lt;code&gt;node index.js&lt;&#x2F;code&gt;,
it should run at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;localhost:8080&quot;&gt;localhost:8080&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-a-local-database-table-entry&quot;&gt;Create a local database, table &amp;amp; entry&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;sudo -iu postgres
createdb -O postgres node-postgres-pg
psql -d node-postgres-pg
\conninfo
CREATE TABLE users(id SERIAL PRIMARY KEY, nickname TEXT NOT NULL);
INSERT INTO users(nickname) VALUES (&amp;#x27;miku86&amp;#x27;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Test your database with &lt;code&gt;SELECT * FROM users;&lt;&#x2F;code&gt;,
there should be &lt;code&gt;1 row&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-database-js-with-a-generic-query&quot;&gt;Create &lt;code&gt;database.js&lt;&#x2F;code&gt; with a generic query&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const { Pool } = require(&amp;quot;pg&amp;quot;);
&amp;#x2F;&amp;#x2F; your credentials
DATABASE_URL =
  &amp;quot;postgres:&amp;#x2F;&amp;#x2F;[db-user]:[password]@127.0.0.1:5432&amp;#x2F;node-postgres-pg&amp;quot;;

const pool = new Pool({
  connectionString: DATABASE_URL,
});

&amp;#x2F;&amp;#x2F; a generic query, that executes all queries you send to it
function query(text) {
  return new Promise((resolve, reject) =&amp;gt; {
    pool
      .query(text)
      .then((res) =&amp;gt; {
        resolve(res);
      })
      .catch((err) =&amp;gt; {
        reject(err);
      });
  });
}

module.exports = {
  query,
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: This implementation is very simple and not for production. You should never move your credentials into this file, you should use something like &lt;code&gt;dotenv&lt;&#x2F;code&gt;. You should also move the database config into a separate file. But for the sake of simplicity, I make this example as simple as possible.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-user-js-with-one-method-to-read-all-database-rows&quot;&gt;Create &lt;code&gt;User.js&lt;&#x2F;code&gt; with one method to read all database rows&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const database = require(&amp;quot;.&amp;#x2F;database&amp;quot;);

const User = {
  async readAll(req, res) {
    try {
      const readAllQuery = &amp;quot;SELECT * FROM users&amp;quot;;
      const { rows } = await database.query(readAllQuery);
      return res.send({ rows });
    } catch (error) {
      return res.send(error);
    }
  },
};

module.exports = User;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A User object, that has one method &lt;code&gt;readAll()&lt;&#x2F;code&gt;.
This method sends a PostgreSQL query (&lt;code&gt;SELECT * FROM users&lt;&#x2F;code&gt;) to the generic query in &lt;code&gt;database.js&lt;&#x2F;code&gt; (we imported it at the top) and awaits the response, where it destructures the &lt;code&gt;rows&lt;&#x2F;code&gt; and returns them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;update-index-js-with-a-new-route&quot;&gt;Update &lt;code&gt;index.js&lt;&#x2F;code&gt; with a new route&lt;&#x2F;h2&gt;
&lt;p&gt;We now have to add the &lt;code&gt;users&lt;&#x2F;code&gt; endpoint to &lt;code&gt;index.js&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const express = require(&amp;quot;express&amp;quot;);
&amp;#x2F;&amp;#x2F; new: import User
const User = require(&amp;quot;.&amp;#x2F;User&amp;quot;);
const app = express();
const PORT = 8080;

app.get(&amp;quot;&amp;#x2F;&amp;quot;, (req, res) =&amp;gt; {
  res.send({ message: &amp;quot;endpoint working&amp;quot; });
});

&amp;#x2F;&amp;#x2F; new: route to users, that runs readAll()
app.get(&amp;quot;&amp;#x2F;users&amp;quot;, User.readAll);

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Test your server with &lt;code&gt;node index.js&lt;&#x2F;code&gt;,
it should run at &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;localhost:8080&#x2F;users&quot;&gt;localhost:8080&#x2F;users&lt;&#x2F;a&gt; and show all (= 1) rows from the PostgreSQL database.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;&#x2F;h2&gt;
&lt;p&gt;In then end, we did these steps:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;created an express server&lt;&#x2F;li&gt;
&lt;li&gt;created a database with one table and content&lt;&#x2F;li&gt;
&lt;li&gt;created a method to read the content&lt;&#x2F;li&gt;
&lt;li&gt;added a route that runs this method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;To setup additional database queries, we only have to:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;add a new method in &lt;code&gt;User.js&lt;&#x2F;code&gt; with a new query (&lt;code&gt;INSERT&lt;&#x2F;code&gt;, &lt;code&gt;DELETE&lt;&#x2F;code&gt; etc.)&lt;&#x2F;li&gt;
&lt;li&gt;add a new route in &lt;code&gt;index.js&lt;&#x2F;code&gt; that runs the new method&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will learn how to use an &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Object-relational_mapping&quot;&gt;ORM&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;&quot;&gt;Express Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;pg&quot;&gt;pg at npm&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;node-postgres.com&#x2F;&quot;&gt;pg docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL: How To Connect Two Tables (Joins)</title>
        <published>2019-09-11T00:00:00+00:00</published>
        <updated>2019-09-11T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-11/" type="text/html"/>
        <id>https://miku86.com/2019-09-11/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;We learned:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-create-our-first-table-1j82&quot;&gt;how to create a table &lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-create-some-basic-queries-57l8&quot;&gt;how to create simple queries&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Now we want to learn how to connect two tables.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;connect-to-the-database-shell&quot;&gt;Connect to the Database Shell&lt;&#x2F;h2&gt;
&lt;p&gt;First, I connect to my database&#x27;s shell:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;psql -d miku86-db
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-two-tables&quot;&gt;Create Two Tables&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;table-1-breed&quot;&gt;Table 1: &lt;code&gt;breed&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Create table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# CREATE TABLE breed (breed_id SERIAL PRIMARY KEY, breed_name TEXT NOT NULL);
CREATE TABLE
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Every &lt;code&gt;breed&lt;&#x2F;code&gt; must have a &lt;code&gt;breed_id&lt;&#x2F;code&gt; (unique) and a &lt;code&gt;breed_name&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Add data into table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# INSERT INTO breed (breed_name) VALUES (&amp;#x27;Labrador&amp;#x27;);
INSERT 0 1
miku86-db=# INSERT INTO breed (breed_name) VALUES (&amp;#x27;Poodle&amp;#x27;);
INSERT 0 1
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Check table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM breed;
 breed_id | breed_name
----------+------------
        1 | Labrador
        2 | Poodle
(2 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We created two breeds, both have a &lt;code&gt;breed_id&lt;&#x2F;code&gt; and a &lt;code&gt;breed_name&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;table-2-dog&quot;&gt;Table 2: &lt;code&gt;dog&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;ul&gt;
&lt;li&gt;Create table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# CREATE TABLE dog (dog_id SERIAL PRIMARY KEY, dog_name TEXT NOT NULL, breed_id INT REFERENCES breed(breed_id));
CREATE TABLE
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Every &lt;code&gt;dog&lt;&#x2F;code&gt; must have a &lt;code&gt;dog_id&lt;&#x2F;code&gt; (unique) and a &lt;code&gt;dog_name&lt;&#x2F;code&gt;, and can have a &lt;code&gt;breed_id&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Add data into table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# INSERT INTO dog (dog_name, breed_id) VALUES (&amp;#x27;Rex&amp;#x27;, 1);
INSERT 0 1
miku86-db=# INSERT INTO dog (dog_name) VALUES (&amp;#x27;Anny&amp;#x27;);
INSERT 0 1
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Check table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM dog;
 dog_id | dog_name | breed_id
--------+----------+----------
      1 | Rex      |        1
      2 | Anny     |
(2 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;We created two dogs, both have a &lt;code&gt;dog_id&lt;&#x2F;code&gt; and a &lt;code&gt;dog_name&lt;&#x2F;code&gt;,
but only &lt;code&gt;Rex&lt;&#x2F;code&gt; has a &lt;code&gt;breed_id&lt;&#x2F;code&gt;, &lt;code&gt;Anny&lt;&#x2F;code&gt; doesn&#x27;t (perhaps we couldn&#x27;t figure it out).&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;connect-the-tables&quot;&gt;Connect The Tables&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;every-row-in-the-left-table-that-matchs-with-a-row-in-the-right-table-inner-join&quot;&gt;Every row in the left table that matchs with a row in the right table: Inner Join&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM dog JOIN breed ON dog.breed_id = breed.breed_id;
 dog_id | dog_name | breed_id | breed_id | breed_name
--------+----------+----------+----------+------------
      1 | Rex      |        1 |        1 | Labrador
(1 row)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;Rex&lt;&#x2F;code&gt; has a &lt;code&gt;breed_id&lt;&#x2F;code&gt;, that exists in the &lt;code&gt;breed&lt;&#x2F;code&gt; table,
therefore he is &lt;em&gt;displayed&lt;&#x2F;em&gt;.
&lt;code&gt;Anny&lt;&#x2F;code&gt; does not, therefore she is &lt;em&gt;not displayed&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;every-row-from-the-left-table-left-join&quot;&gt;Every row from the left table: Left Join&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM dog LEFT JOIN breed ON dog.breed_id = breed.breed_id;
 dog_id | dog_name | breed_id | breed_id | breed_name
--------+----------+----------+----------+------------
      1 | Rex      |        1 |        1 | Labrador
      2 | Anny     |          |          |
(2 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;Rex&lt;&#x2F;code&gt; is in the left table, therefore he is &lt;em&gt;displayed&lt;&#x2F;em&gt;.
&lt;code&gt;Anny&lt;&#x2F;code&gt; is in the left table, therefore she is &lt;em&gt;displayed&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;every-row-from-the-right-table-right-join&quot;&gt;Every row from the right table: Right Join&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM dog RIGHT JOIN breed ON dog.breed_id = breed.breed_id;
 dog_id | dog_name | breed_id | breed_id | breed_name
--------+----------+----------+----------+------------
      1 | Rex      |        1 |        1 | Labrador
        |          |          |        2 | Poodle
(2 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;Labrador&lt;&#x2F;code&gt; is in the right table, therefore it is &lt;em&gt;displayed&lt;&#x2F;em&gt;.
&lt;code&gt;Poodle&lt;&#x2F;code&gt; is in the right table, therefore it is &lt;em&gt;displayed&lt;&#x2F;em&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;every-row-from-the-left-table-every-row-from-the-right-table-full-join&quot;&gt;Every row from the left table &amp;amp; every row from the right table: Full Join&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM dog FULL JOIN breed ON dog.breed_id = breed.breed_id;
 dog_id | dog_name | breed_id | breed_id | breed_name
--------+----------+----------+----------+------------
      1 | Rex      |        1 |        1 | Labrador
      2 | Anny     |          |          |
        |          |          |        2 | Poodle
(3 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;graphical-visualization&quot;&gt;Graphical Visualization&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;www.postgresqltutorial.com&#x2F;postgresql-joins&#x2F;&quot;&gt;Here&lt;&#x2F;a&gt; is a great graphical visualization of the various Joins.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;&quot;&gt;PostgreSQL Homepage&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;tutorial-join.html&quot;&gt;Joins Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;www.postgresqltutorial.com&#x2F;postgresql-joins&#x2F;&quot;&gt;Graphical Visualization&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL: How To Update &amp; Delete Data</title>
        <published>2019-09-10T00:00:00+00:00</published>
        <updated>2019-09-10T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-10/" type="text/html"/>
        <id>https://miku86.com/2019-09-10/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-read-from-write-to-our-table-48kg&quot;&gt;how to create simple queries&lt;&#x2F;a&gt; to read &amp;amp; write some data.&lt;&#x2F;p&gt;
&lt;p&gt;We also learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-create-some-basic-queries-57l8&quot;&gt;how to filter &amp;amp; order our data&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to update &amp;amp; delete data.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;connect-to-the-database-shell&quot;&gt;Connect to the Database Shell&lt;&#x2F;h2&gt;
&lt;p&gt;First, I connect to my created database shell:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;psql -d miku86-db
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;read-show-all-data-in-person-table&quot;&gt;Read: Show All Data In &lt;code&gt;person&lt;&#x2F;code&gt;-table&lt;&#x2F;h2&gt;
&lt;p&gt;Then, I check my current table:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person;
 id | nickname | country | available
----+----------+---------+-----------
  1 | miku86   | germany | t
  2 | heidi    | austria | t
  3 | tom      | usa     | f
  4 | pavel    | russia  | f
(4 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I &lt;code&gt;SELECT&lt;&#x2F;code&gt; all (&lt;code&gt;*&lt;&#x2F;code&gt; = wildcard) rows &lt;code&gt;FROM&lt;&#x2F;code&gt; the &lt;code&gt;person&lt;&#x2F;code&gt;-table.
There are &lt;code&gt;4 rows&lt;&#x2F;code&gt; in it.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;delete-a-row&quot;&gt;Delete A Row&lt;&#x2F;h2&gt;
&lt;p&gt;Simplified Syntax:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;DELETE FROM [table] WHERE [expression];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;example-1-delete-the-person-s-with-the-id-of-1&quot;&gt;Example #1: Delete the person(s) with the &lt;code&gt;id&lt;&#x2F;code&gt; of &lt;code&gt;1&lt;&#x2F;code&gt;:&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# DELETE FROM person WHERE id = 1;
DELETE 1
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can see &lt;code&gt;DELETE 1&lt;&#x2F;code&gt; below the &lt;code&gt;DELETE&lt;&#x2F;code&gt;-query.
The command executed successfully, &lt;code&gt;1&lt;&#x2F;code&gt; row was deleted.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person;
 id | nickname | country | available
----+----------+---------+-----------
  2 | heidi    | austria | t
  3 | tom      | usa     | f
  4 | pavel    | russia  | f
(3 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The person with the &lt;code&gt;id&lt;&#x2F;code&gt; of &lt;code&gt;1&lt;&#x2F;code&gt; was deleted.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h3 id=&quot;example-2-delete-the-person-s-that-are-not-available-available-false&quot;&gt;Example #2: Delete the person(s) that are not available (=&amp;gt; available = false):&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# DELETE FROM person WHERE available = false;
DELETE 2
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can see &lt;code&gt;DELETE 2&lt;&#x2F;code&gt; below the &lt;code&gt;DELETE&lt;&#x2F;code&gt;-query.
The command executed successfully, &lt;code&gt;2&lt;&#x2F;code&gt; rows were deleted.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person;
 id | nickname | country | available
----+----------+---------+-----------
  2 | heidi    | austria | t
(1 row)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The person with the &lt;code&gt;id&lt;&#x2F;code&gt; of &lt;code&gt;1&lt;&#x2F;code&gt; was deleted in example 1.
The persons with &lt;code&gt;available&lt;&#x2F;code&gt; of &lt;code&gt;f&lt;&#x2F;code&gt; (= false) were deleted in this example.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;update-a-row&quot;&gt;Update A Row&lt;&#x2F;h2&gt;
&lt;p&gt;Simplified Syntax:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;UPDATE [table] SET [col] = [newvalue] WHERE [expression];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;example-1-update-the-person-s-with-country-of-austria-to-country-of-germany&quot;&gt;Example #1: Update the person(s) with &lt;code&gt;country&lt;&#x2F;code&gt; of &lt;code&gt;austria&lt;&#x2F;code&gt; to &lt;code&gt;country&lt;&#x2F;code&gt; of &lt;code&gt;germany&lt;&#x2F;code&gt;:&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# UPDATE person SET country = &amp;#x27;germany&amp;#x27; WHERE country = &amp;#x27;austria&amp;#x27;;
UPDATE 1
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can see &lt;code&gt;UPDATE 1&lt;&#x2F;code&gt; below the &lt;code&gt;UPDATE&lt;&#x2F;code&gt;-query.
The command executed successfully, &lt;code&gt;1&lt;&#x2F;code&gt; row was updated.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person;
 id | nickname | country | available
----+----------+---------+-----------
  2 | heidi    | germany | t
(1 row)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The person with the &lt;code&gt;country&lt;&#x2F;code&gt; of &lt;code&gt;austria&lt;&#x2F;code&gt; was updated to the &lt;code&gt;country&lt;&#x2F;code&gt; of &lt;code&gt;germany&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will learn how to connect two tables.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-delete.html&quot;&gt;Delete Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-update.html&quot;&gt;Update Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL: How To Create Some Basic Queries</title>
        <published>2019-09-09T00:00:00+00:00</published>
        <updated>2019-09-09T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-09/" type="text/html"/>
        <id>https://miku86.com/2019-09-09/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-read-from-write-to-our-table-48kg&quot;&gt;how to create simple queries&lt;&#x2F;a&gt; to read &amp;amp; write some data.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to have a look at some of the additional methods to create some basic queries.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;connect-to-the-database-shell&quot;&gt;Connect to the Database Shell&lt;&#x2F;h2&gt;
&lt;p&gt;First, I connect to my created database shell:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;psql -d miku86-db
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;read-show-all-data-in-person-table-again&quot;&gt;Read: Show All Data In &lt;code&gt;person&lt;&#x2F;code&gt;-table again:&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;I created a new &lt;code&gt;person&lt;&#x2F;code&gt;-table to have some more columns:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# CREATE TABLE person (id SERIAL PRIMARY KEY, nickname TEXT NOT NULL, country TEXT, available BOOLEAN NOT NULL);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# \d person
                              Table &amp;quot;public.person&amp;quot;
  Column   |  Type   | Collation | Nullable |              Default
-----------+---------+-----------+----------+------------------------------------
 id        | integer |           | not null | nextval(&amp;#x27;person_id_seq&amp;#x27;::regclass)
 nickname  | text    |           | not null |
 country   | text    |           |          |
 available | boolean |           | not null |
Indexes:
    &amp;quot;person_pkey&amp;quot; PRIMARY KEY, btree (id)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;And I added some rows:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# INSERT INTO person(nickname, country, available) VALUES (&amp;#x27;miku86&amp;#x27;, &amp;#x27;germany&amp;#x27;, true);
miku86-db=# INSERT INTO person(nickname, country, available) VALUES (&amp;#x27;heidi&amp;#x27;, &amp;#x27;austria&amp;#x27;, true);
miku86-db=# INSERT INTO person(nickname, country, available) VALUES (&amp;#x27;tom&amp;#x27;, &amp;#x27;usa&amp;#x27;, false);
miku86-db=# INSERT INTO person(nickname, country, available) VALUES (&amp;#x27;pavel&amp;#x27;, &amp;#x27;russia&amp;#x27;, false);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Showing all rows:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person;
 id | nickname | country | available
----+----------+---------+-----------
  1 | miku86   | germany | t
  2 | heidi    | austria | t
  3 | tom      | usa     | f
  4 | pavel    | russia  | f
(4 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I &lt;code&gt;SELECT&lt;&#x2F;code&gt; all (&lt;code&gt;*&lt;&#x2F;code&gt; = wildcard) rows &lt;code&gt;FROM&lt;&#x2F;code&gt; the &lt;code&gt;person&lt;&#x2F;code&gt;-table.
There are &lt;code&gt;4 rows&lt;&#x2F;code&gt; in it.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;show-specific-columns&quot;&gt;Show Specific Columns&lt;&#x2F;h2&gt;
&lt;p&gt;Sometimes we want to show only specific columns.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;example-1-show-all-persons-but-only-the-columns-for-nickname-and-country&quot;&gt;Example #1: Show all persons, but only the columns for &lt;code&gt;nickname&lt;&#x2F;code&gt; and &lt;code&gt;country&lt;&#x2F;code&gt;:&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT nickname, country FROM person;
 nickname | country
----------+---------
 miku86   | germany
 heidi    | austria
 tom      | usa
 pavel    | russia
(4 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;where-clause&quot;&gt;&lt;code&gt;WHERE&lt;&#x2F;code&gt; Clause&lt;&#x2F;h2&gt;
&lt;p&gt;Sometimes we want to show only specific results.
That&#x27;s where the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;queries-table-expressions.html#QUERIES-WHERE&quot;&gt;&lt;code&gt;WHERE&lt;&#x2F;code&gt; clause&lt;&#x2F;a&gt; comes in handy.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;SELECT * FROM [table] WHERE [expression];
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;example-1-show-persons-with-the-id-of-1&quot;&gt;Example #1: Show persons with the &lt;code&gt;id&lt;&#x2F;code&gt; of &lt;code&gt;1&lt;&#x2F;code&gt;:&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person WHERE id = 1;
 id | nickname | country | available
----+----------+---------+-----------
  1 | miku86   | germany | t
(1 row)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In this case, the expression is &lt;code&gt;id = 1&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;example-2-show-persons-that-are-not-available-available-false&quot;&gt;Example #2: Show persons that are not available (=&amp;gt; available = false):&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person WHERE available = false;
 id | nickname | country | available
----+----------+---------+-----------
  3 | tom      | usa     | f
  4 | pavel    | russia  | f
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: Booleans accepts multiple representations, e.g. &lt;code&gt;&#x27;f&#x27;&lt;&#x2F;code&gt;, &lt;code&gt;&#x27;no&#x27;&lt;&#x2F;code&gt;, &lt;code&gt;&#x27;0&#x27;&lt;&#x2F;code&gt;. &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;datatype-boolean.html&quot;&gt;Read the docs&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;limit-clause&quot;&gt;&lt;code&gt;LIMIT&lt;&#x2F;code&gt; Clause&lt;&#x2F;h2&gt;
&lt;p&gt;Sometimes we want to limit the results.
That&#x27;s where the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-select.html#SQL-LIMIT&quot;&gt;&lt;code&gt;LIMIT&lt;&#x2F;code&gt; clause&lt;&#x2F;a&gt; comes in handy.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;example-1-show-all-persons-but-at-maximum-2&quot;&gt;Example #1: Show all persons, but at maximum 2:&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person LIMIT 2;
 id | nickname | country | available
----+----------+---------+-----------
  1 | miku86   | germany | t
  2 | heidi    | austria | t
(2 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Without &lt;code&gt;LIMIT 2&lt;&#x2F;code&gt;, we would see 4 rows, but we limit it to 2 rows.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;order-by&quot;&gt;&lt;code&gt;ORDER BY&lt;&#x2F;code&gt;&lt;&#x2F;h2&gt;
&lt;p&gt;Sometimes we want to order&#x2F;sort the results.
That&#x27;s where the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;queries-order.html&quot;&gt;&lt;code&gt;ORDER BY&lt;&#x2F;code&gt; Docs&lt;&#x2F;a&gt; comes in handy.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;example-1-show-all-persons-and-order-them-by-their-country-ascending&quot;&gt;Example #1: Show all persons and order them by their country (ascending):&lt;&#x2F;h3&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person ORDER BY country;
 id | nickname | country | available
----+----------+---------+-----------
  2 | heidi    | austria | t
  1 | miku86   | germany | t
  4 | pavel    | russia  | f
  3 | tom      | usa     | f
(4 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will learn how to update and delete data.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;datatype.html&quot;&gt;PostgreSQL Data Types&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;queries-select-lists.html#QUERIES-SELECT-LIST-ITEMS&quot;&gt;Select-List Items Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;queries-table-expressions.html#QUERIES-WHERE&quot;&gt;&lt;code&gt;WHERE&lt;&#x2F;code&gt; Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-select.html#SQL-LIMIT&quot;&gt;&lt;code&gt;LIMIT&lt;&#x2F;code&gt; Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;queries-order.html&quot;&gt;&lt;code&gt;ORDER BY&lt;&#x2F;code&gt; Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL: How To Read From &amp; Write To Our Table</title>
        <published>2019-09-08T00:00:00+00:00</published>
        <updated>2019-09-08T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-08/" type="text/html"/>
        <id>https://miku86.com/2019-09-08/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-what-is-it-how-to-install-it-16hk&quot;&gt;installed&lt;&#x2F;a&gt; and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-setup-our-installed-postgresql-39hf&quot;&gt;setup&lt;&#x2F;a&gt; PostgreSQL on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;We also learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-create-our-first-table-1j82&quot;&gt;how to create a table&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to read from &amp;amp; write to our table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;connect-to-the-database-shell&quot;&gt;Connect to the Database Shell&lt;&#x2F;h2&gt;
&lt;p&gt;First, I connect to my created database shell:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;psql -d miku86-db
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Result:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=#
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;check-table&quot;&gt;Check Table&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Display tables of database:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# \dt
         List of relations
 Schema |  Name  | Type  |  Owner
--------+--------+-------+----------
 public | person | table | miku86
(1 row)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Display overview of &lt;code&gt;person&lt;&#x2F;code&gt;-table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# \d person
                             Table &amp;quot;public.person&amp;quot;
  Column  |  Type   | Collation | Nullable |              Default
----------+---------+-----------+----------+------------------------------------
 id       | integer |           | not null | nextval(&amp;#x27;person_id_seq&amp;#x27;::regclass)
 nickname | text    |           | not null |
Indexes:
    &amp;quot;person_pkey&amp;quot; PRIMARY KEY, btree (id)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;read-show-all-data-in-person-table&quot;&gt;Read: Show All Data In &lt;code&gt;person&lt;&#x2F;code&gt;-table:&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person;
 id | nickname
----+----------
(0 rows)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I &lt;code&gt;SELECT&lt;&#x2F;code&gt; all (&lt;code&gt;*&lt;&#x2F;code&gt; = wildcard) rows &lt;code&gt;FROM&lt;&#x2F;code&gt; the &lt;code&gt;person&lt;&#x2F;code&gt;-table.
Because we didn&#x27;t add any data yet, there is nothing to show (= &lt;code&gt;0 rows&lt;&#x2F;code&gt;).&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;write-add-data-to-person-table&quot;&gt;Write: Add Data To &lt;code&gt;person&lt;&#x2F;code&gt;-table:&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Check which columns exist and which data types they need:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# \d person
                             Table &amp;quot;public.person&amp;quot;
  Column  |  Type   | Collation | Nullable |              Default
----------+---------+-----------+----------+------------------------------------
 id       | integer |           | not null | nextval(&amp;#x27;person_id_seq&amp;#x27;::regclass)
 nickname | text    |           | not null |
Indexes:
    &amp;quot;person_pkey&amp;quot; PRIMARY KEY, btree (id)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Column &lt;code&gt;id&lt;&#x2F;code&gt; needs an &lt;code&gt;integer&lt;&#x2F;code&gt;, column &lt;code&gt;nickname&lt;&#x2F;code&gt; needs a &lt;code&gt;text&lt;&#x2F;code&gt;.
The &lt;code&gt;primary key&lt;&#x2F;code&gt; of the &lt;code&gt;person&lt;&#x2F;code&gt;-table is &lt;code&gt;id&lt;&#x2F;code&gt;, therefore it has to be unique and not null.&lt;&#x2F;p&gt;
&lt;p&gt;Read the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;datatype.html&quot;&gt;docs about all data types&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Add a new entry (=row) to the table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# INSERT INTO person (id, nickname) VALUES (1, &amp;#x27;miku86&amp;#x27;);
INSERT 0 1
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;INSERT&lt;&#x2F;code&gt; &lt;code&gt;INTO&lt;&#x2F;code&gt; the &lt;code&gt;person&lt;&#x2F;code&gt;-table to column &lt;code&gt;id&lt;&#x2F;code&gt; value &lt;code&gt;1&lt;&#x2F;code&gt; and to column &lt;code&gt;nickname&lt;&#x2F;code&gt; value &lt;code&gt;miku86&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;read-show-all-data-in-person-table-again&quot;&gt;Read: Show All Data In &lt;code&gt;person&lt;&#x2F;code&gt;-table again:&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;sql&quot; class=&quot;language-sql &quot;&gt;&lt;code class=&quot;language-sql&quot; data-lang=&quot;sql&quot;&gt;miku86-db=# SELECT * FROM person;
 id | nickname
----+----------
  1 | miku86
(1 row)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I &lt;code&gt;SELECT&lt;&#x2F;code&gt; all (&lt;code&gt;*&lt;&#x2F;code&gt; = wildcard) rows &lt;code&gt;FROM&lt;&#x2F;code&gt; the &lt;code&gt;person&lt;&#x2F;code&gt;-table.
There is &lt;code&gt;1 row&lt;&#x2F;code&gt; in it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will do some more reading from our table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;datatype.html&quot;&gt;PostgreSQL Data Types&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What happens when you insert a new row with an existing &lt;code&gt;id&lt;&#x2F;code&gt;?&lt;&#x2F;li&gt;
&lt;li&gt;Do you always need to write down all columns?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL: How To Create Our First Table</title>
        <published>2019-09-06T00:00:00+00:00</published>
        <updated>2019-09-06T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-06/" type="text/html"/>
        <id>https://miku86.com/2019-09-06/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-what-is-it-how-to-install-it-16hk&quot;&gt;installed&lt;&#x2F;a&gt; and &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-setup-our-installed-postgresql-39hf&quot;&gt;setup&lt;&#x2F;a&gt; PostgreSQL on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to create our first table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;connect-to-the-database-shell&quot;&gt;Connect to the Database Shell&lt;&#x2F;h2&gt;
&lt;p&gt;We&#x27;ve just created a user and a database in the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-how-to-setup-our-installed-postgresql-39hf&quot;&gt;setup article&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we can connect to the database shell:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;psql -d [db]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;My result, because I created a database &amp;quot;miku86-db&amp;quot; earlier:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;miku86-db=#
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;app-psql.html&quot;&gt;psql&lt;&#x2F;a&gt; is a terminal-based front-end to PostgreSQL, you can type in queries, issue them to PostgreSQL, and see the query results.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;basic-commands&quot;&gt;Basic Commands&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;psql help: &lt;code&gt;help&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;psql commands: &lt;code&gt;\?&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;SQL commands: &lt;code&gt;\h&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;quit psql: &lt;code&gt;\q&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;current connection info: &lt;code&gt;\conninfo&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;list of databases: &lt;code&gt;\l&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;connect to a database: &lt;code&gt;\c [dbname]&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;create database: &lt;code&gt;CREATE DATABASE [db];&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;delete database: &lt;code&gt;DROP DATABASE [db];&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;display tables of database: &lt;code&gt;\dt&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;display overview of table: &lt;code&gt;\d [table]&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;create table: &lt;code&gt;CREATE TABLE [table]([col][datatype] [constraints])&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-our-first-table&quot;&gt;Create Our First Table&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Check my current connection:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;miku86-db=# \conninfo
You are connected to database &amp;quot;miku86-db&amp;quot; as user &amp;quot;miku86&amp;quot; via socket in &amp;quot;&amp;#x2F;run&amp;#x2F;postgresql&amp;quot; at port &amp;quot;5432&amp;quot;.
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Display tables of database:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;miku86-db=# \dt
Did not find any relations.
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Create table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;miku86-db=# CREATE TABLE person (id SERIAL PRIMARY KEY, nickname TEXT NOT NULL);
CREATE TABLE
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;I just created a table in my database with two columns:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;column #1: an &lt;code&gt;id&lt;&#x2F;code&gt;, that is a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;datatype-numeric.html&quot;&gt;&lt;code&gt;SERIAL&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; (= an &lt;code&gt;integer&lt;&#x2F;code&gt;, that always gets increased by &lt;code&gt;1&lt;&#x2F;code&gt;) and that is a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;ddl-constraints.html#DDL-CONSTRAINTS-PRIMARY-KEYS&quot;&gt;&lt;code&gt;PRIMARY KEY&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, meaning that &lt;code&gt;id&lt;&#x2F;code&gt; is a unique identifier for a row in the table, therefore the value is unique and not null&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;column #2: a &lt;code&gt;nickname&lt;&#x2F;code&gt;, that is a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;datatype-character.html&quot;&gt;&lt;code&gt;TEXT&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; (= variable and unlimited in its length) and that is &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;ddl-constraints.html#id-1.5.4.5.6&quot;&gt;&lt;code&gt;NOT NULL&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, meaning that &lt;code&gt;nickname&lt;&#x2F;code&gt; can&#x27;t be missing.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;ul&gt;
&lt;li&gt;Display overview of table:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;miku86-db=# \d person
                             Table &amp;quot;public.person&amp;quot;
  Column  |  Type   | Collation | Nullable |              Default
----------+---------+-----------+----------+------------------------------------
 id       | integer |           | not null | nextval(&amp;#x27;person_id_seq&amp;#x27;::regclass)
 nickname | text    |           | not null |
Indexes:
    &amp;quot;person_pkey&amp;quot; PRIMARY KEY, btree (id)
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will read &amp;amp; write from&#x2F;to our table.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;&quot;&gt;PostgreSQL Homepage&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;datatype.html&quot;&gt;PostgreSQL Data Types&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;ddl-constraints.html&quot;&gt;PostgreSQL Constraints&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What&#x27;s your favorite SQL database?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL: How To Setup Our Installed PostgreSQL</title>
        <published>2019-09-05T00:00:00+00:00</published>
        <updated>2019-09-05T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-05/" type="text/html"/>
        <id>https://miku86.com/2019-09-05/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;postgresql-what-is-it-how-to-install-it-16hk&quot;&gt;installed PostgreSQL&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to setup our installed PostgreSQL.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-a-new-postgresql-database-cluster&quot;&gt;Create a new PostgreSQL database cluster&lt;&#x2F;h2&gt;
&lt;p&gt;initdb must be run as the user that will own the server process, therefore it is recommended to create a new user and login with it.&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;# login as user
sudo -iu [username]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;initdb creates a new PostgreSQL database cluster (a collection of databases that are managed by a single server instance).&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;initdb -D &amp;#x2F;var&amp;#x2F;lib&amp;#x2F;postgres&amp;#x2F;data
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you get &lt;code&gt;permission denied&lt;&#x2F;code&gt;, you can find a solutin in the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;app-initdb.html&quot;&gt;initdb docs&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;start-postgresql-server&quot;&gt;Start PostgreSQL server&lt;&#x2F;h2&gt;
&lt;p&gt;If you don&#x27;t know how to start a system service, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;tableplus.com&#x2F;blog&#x2F;2018&#x2F;10&#x2F;how-to-start-stop-restart-postgresql-server.html&quot;&gt;read this&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Example for Arch:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;systemctl start postgresql
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you get some problems, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;server-start.html&quot;&gt;read this&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-a-role-database-user&quot;&gt;Create a Role (= Database User)&lt;&#x2F;h2&gt;
&lt;p&gt;Now we need a role, that can do some operations.&lt;&#x2F;p&gt;
&lt;p&gt;Don&#x27;t forget to be logged in as the user you created before:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;# login as user
sudo -iu [username]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Create user:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;createuser --interactive
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;11&#x2F;app-createuser.html&quot;&gt;createuser docs&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;create-a-database&quot;&gt;Create a Database&lt;&#x2F;h2&gt;
&lt;p&gt;No we need a database, that is owned by our new user&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;createdb -O [username] [dbname]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;connect-to-the-database-shell&quot;&gt;Connect to the Database Shell&lt;&#x2F;h2&gt;
&lt;p&gt;We&#x27;ve just created a user and a database.&lt;&#x2F;p&gt;
&lt;p&gt;Now we can connect to the database shell:&lt;&#x2F;p&gt;
&lt;pre&gt;&lt;code&gt;psql -d [dbname]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;app-psql.html&quot;&gt;psql&lt;&#x2F;a&gt; is a terminal-based front-end to PostgreSQL, you can type in queries, issue them to PostgreSQL, and see the query results.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-part&quot;&gt;Next Part&lt;&#x2F;h2&gt;
&lt;p&gt;We will write our first commands to get some data.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;&quot;&gt;PostgreSQL Homepage&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;index.html&quot;&gt;PostgreSQL Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What&#x27;s your favorite SQL database?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>PostgreSQL: What is it &amp; How To Install it</title>
        <published>2019-09-04T00:00:00+00:00</published>
        <updated>2019-09-04T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-04/" type="text/html"/>
        <id>https://miku86.com/2019-09-04/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;I am creating a new series about PostgreSQL.&lt;&#x2F;p&gt;
&lt;p&gt;In this short article, we will learn how to install it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;what-is-postgresql&quot;&gt;What is PostgreSQL?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;a free and open-source &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Relational_database&quot;&gt;relational database management system (RDBMS)&lt;&#x2F;a&gt; to manage data&lt;&#x2F;li&gt;
&lt;li&gt;primarly uses &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL&quot;&gt;SQL (Structured Query Language)&lt;&#x2F;a&gt; to write commands&lt;&#x2F;li&gt;
&lt;li&gt;primarly stores data in tables consisting columns and rows&lt;&#x2F;li&gt;
&lt;li&gt;can get easily connected to backend applications (e.g. in Node, Python, Java etc.)&lt;&#x2F;li&gt;
&lt;li&gt;comes with a terminal-based front-end named &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;9.3&#x2F;app-psql.html&quot;&gt;psql&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;how-to-install-it&quot;&gt;How To Install it?&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;windows&quot;&gt;Windows&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Go to the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;download&#x2F;windows&quot;&gt;PostgreSQL download page&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Follow the instructions&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;macos&quot;&gt;macOS&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Go to the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;download&#x2F;macosx&quot;&gt;PostgreSQL download page&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Follow the instructions&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;ubuntu&quot;&gt;Ubuntu&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Go to the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;download&#x2F;linux&#x2F;ubuntu&quot;&gt;PostgreSQL download page&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Follow the instructions&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;arch&quot;&gt;Arch&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;pacman -S postgresql&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;&quot;&gt;PostgreSQL Homepage&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.postgresql.org&#x2F;download&#x2F;&quot;&gt;PostgreSQL Download&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;PostgreSQL&quot;&gt;PostgreSQL on Wikipedia&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;SQL_syntax&quot;&gt;SQL Syntax&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What&#x27;s your favorite SQL database?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Add Additional Middleware To Our Express Server</title>
        <published>2019-09-03T00:00:00+00:00</published>
        <updated>2019-09-03T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-03/" type="text/html"/>
        <id>https://miku86.com/2019-09-03/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;We also learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-create-a-simple-server-using-express-1n9d&quot;&gt;how to create a simple server using express&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to add additional middleware to our express server.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;reuse-our-simple-server-from-the-last-article&quot;&gt;Reuse our simple server from the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-create-a-simple-server-using-express-1n9d&quot;&gt;last article&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const express = require(&amp;quot;express&amp;quot;);
const app = express();

const PORT = 8080;

app.get(&amp;quot;&amp;#x2F;&amp;quot;, (request, response) =&amp;gt; {
  response.send(&amp;quot;Hello World&amp;quot;);
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: This is our starting point, we have one working route.
I updated &lt;code&gt;req&lt;&#x2F;code&gt; to &lt;code&gt;request&lt;&#x2F;code&gt; &amp;amp; &lt;code&gt;res&lt;&#x2F;code&gt; to &lt;code&gt;response&lt;&#x2F;code&gt; to increase readability.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;additional-middleware&quot;&gt;Additional Middleware&lt;&#x2F;h2&gt;
&lt;p&gt;What is Middleware?&lt;&#x2F;p&gt;
&lt;p&gt;Sometimes you want to add additional functionality between the default request-response-cycle. Let&#x27;s say you want to get some detailed information about the current request.&lt;&#x2F;p&gt;
&lt;p&gt;You can write a simple middleware, that handles this task, and add it to your express app.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;create-a-middleware&quot;&gt;Create a Middleware&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Create a file named &lt;code&gt;logger.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch logger.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const logger = (req, res, next) =&amp;gt; {
  console.log(
    `Time: ${new Date()} - Method: ${req.method} - Path: ${req.originalUrl}`
  );
  next();
};

module.exports = logger;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Require the new logger in index.js and use the middleware:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import express (after npm install express)
const express = require(&amp;quot;express&amp;quot;);

&amp;#x2F;&amp;#x2F; import the logger
const logger = require(&amp;quot;.&amp;#x2F;logger&amp;quot;);

&amp;#x2F;&amp;#x2F; create new express app and save it as app
const app = express();

&amp;#x2F;&amp;#x2F; server configuration
const PORT = 8080;

&amp;#x2F;&amp;#x2F; use the middleware
app.use(logger);

&amp;#x2F;&amp;#x2F; create a route for the app
app.get(&amp;quot;&amp;#x2F;&amp;quot;, (req, res) =&amp;gt; {
  res.send(&amp;quot;Hello World&amp;quot;);
});

&amp;#x2F;&amp;#x2F; make the server listen to requests
app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Visit: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;localhost:8080&quot;&gt;http:&#x2F;&#x2F;localhost:8080&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;
&lt;p&gt;Console Result:&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Server running at: http:&amp;#x2F;&amp;#x2F;localhost:8080&amp;#x2F;
Time: Tue Sep 03 2019 17:32:30 GMT+0200 (Central European Summer Time) - Method: GET - Path: &amp;#x2F;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;express&quot;&gt;express&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;guide&#x2F;using-middleware.html&quot;&gt;Using Middleware&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;4x&#x2F;api.html#app.use&quot;&gt;app.use()&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;4x&#x2F;api.html#middleware-callback-function-examples&quot;&gt;Middleware callback function examples&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What&#x27;s your favorite middleware for express?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Add Routes To Our Express Server</title>
        <published>2019-09-02T00:00:00+00:00</published>
        <updated>2019-09-02T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-02/" type="text/html"/>
        <id>https://miku86.com/2019-09-02/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;We also learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-create-a-simple-server-using-express-1n9d&quot;&gt;how to create a simple server using express&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to add routes to our express server.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;reuse-our-simple-server-from-the-last-article&quot;&gt;Reuse our simple server from the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-create-a-simple-server-using-express-1n9d&quot;&gt;last article&lt;&#x2F;a&gt;&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const express = require(&amp;quot;express&amp;quot;);
const app = express();

const PORT = 8080;

app.get(&amp;quot;&amp;#x2F;&amp;quot;, (request, response) =&amp;gt; {
  response.send(&amp;quot;Hello World&amp;quot;);
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: This is our starting point, we have one working route.
I updated &lt;code&gt;req&lt;&#x2F;code&gt; to &lt;code&gt;request&lt;&#x2F;code&gt; &amp;amp; &lt;code&gt;res&lt;&#x2F;code&gt; to &lt;code&gt;response&lt;&#x2F;code&gt; to increase readability.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;basic-routing&quot;&gt;Basic Routing&lt;&#x2F;h2&gt;
&lt;p&gt;What is Routing?&lt;&#x2F;p&gt;
&lt;p&gt;Every time a client (e.g. the user&#x27;s browser) requests an app&#x27;s endpoint, the server has to respond.&lt;&#x2F;p&gt;
&lt;p&gt;The client sends a specific &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTTP&#x2F;Methods&quot;&gt;HTTP request method&lt;&#x2F;a&gt;, e.g. &lt;code&gt;GET&lt;&#x2F;code&gt;, and a path, e.g. &lt;code&gt;&#x2F;&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;To respond to this request, our express app needs to know how to respond.&lt;&#x2F;p&gt;
&lt;p&gt;Example from above:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;app.get(&amp;quot;&amp;#x2F;&amp;quot;, (request, response) =&amp;gt; {
  response.send(&amp;quot;Hello World&amp;quot;);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;When our express app gets a &lt;code&gt;get&lt;&#x2F;code&gt;-&lt;code&gt;request&lt;&#x2F;code&gt; to &lt;code&gt;&#x2F;&lt;&#x2F;code&gt;, it &lt;code&gt;send&lt;&#x2F;code&gt;s a &lt;code&gt;response&lt;&#x2F;code&gt; of &lt;code&gt;Hello World&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;We can see all relevant words immediately.&lt;&#x2F;p&gt;
&lt;p&gt;Every route in express has the same syntax:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;app.METHOD(PATH, HANDLER);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;METHOD: Which &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTTP&#x2F;Methods&quot;&gt;HTTP request method&lt;&#x2F;a&gt; was sent by the client? (e.g. &lt;code&gt;GET&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;PATH: Which path does the client request? (e.g. &lt;code&gt;&#x2F;&lt;&#x2F;code&gt;, &lt;code&gt;&#x2F;account&lt;&#x2F;code&gt;, &lt;code&gt;&#x2F;dashboard&lt;&#x2F;code&gt;)&lt;&#x2F;li&gt;
&lt;li&gt;HANDLER: How should the app respond to the request? (e.g. send data back, redirect, log something)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;add-a-new-route&quot;&gt;Add a new route&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Add a new route to &lt;code&gt;&#x2F;welcome&lt;&#x2F;code&gt; for a &lt;code&gt;get&lt;&#x2F;code&gt;-request:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const express = require(&amp;quot;express&amp;quot;);
const app = express();

const PORT = 8080;

app.get(&amp;quot;&amp;#x2F;&amp;quot;, (request, response) =&amp;gt; {
  response.send(&amp;quot;Hello World&amp;quot;);
});

app.get(&amp;quot;&amp;#x2F;welcome&amp;quot;, (request, response) =&amp;gt; {
  response.send(&amp;quot;Welcome!&amp;quot;);
});

app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Console Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Server running at: http:&amp;#x2F;&amp;#x2F;localhost:8080&amp;#x2F;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Visit: &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;http:&#x2F;&#x2F;localhost:8080&#x2F;welcome&quot;&gt;http:&#x2F;&#x2F;localhost:8080&#x2F;welcome&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Client Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;thepracticaldev.s3.amazonaws.com&#x2F;i&#x2F;b289efi4ujff75tzdbb5.png&quot; alt=&quot;Alt Text&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;express&quot;&gt;express&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;starter&#x2F;basic-routing.html&quot;&gt;Basic Routing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;guide&#x2F;routing.html&quot;&gt;Advanced Routing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;HTTP&#x2F;Methods&quot;&gt;HTTP request method&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;your-task&quot;&gt;Your Task&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Create a basic route, that handles a &lt;code&gt;GET&lt;&#x2F;code&gt;-request to &lt;code&gt;&#x2F;dashboard&lt;&#x2F;code&gt;, that &lt;code&gt;responds&lt;&#x2F;code&gt; with &lt;code&gt;This is your dashboard&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;If you want to get some feedback, I invite you to share your code in the comments (beginner) or on Github (advanced)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Create A Simple Server Using Express</title>
        <published>2019-09-01T00:00:00+00:00</published>
        <updated>2019-09-01T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-09-01/" type="text/html"/>
        <id>https://miku86.com/2019-09-01/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;We also learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-create-a-simple-server-using-the-http-module-2ld2&quot;&gt;how to create a simple server using Node&#x27;s HTTP module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;We also know &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-get-external-packages-npm-56oj&quot;&gt;How to Get External Packages&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to create a simple server using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;express&quot;&gt;express&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import express (after npm install express)
const express = require(&amp;quot;express&amp;quot;);

&amp;#x2F;&amp;#x2F; create new express app and save it as &amp;quot;app&amp;quot;
const app = express();

&amp;#x2F;&amp;#x2F; server configuration
const PORT = 8080;

&amp;#x2F;&amp;#x2F; create a route for the app
app.get(&amp;quot;&amp;#x2F;&amp;quot;, (req, res) =&amp;gt; {
  res.send(&amp;quot;Hello World&amp;quot;);
});

&amp;#x2F;&amp;#x2F; make the server listen to requests
app.listen(PORT, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;localhost:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: This simple server has only one working route (&lt;code&gt;&#x2F;&lt;&#x2F;code&gt;). If you want to learn more about Routing, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;guide&#x2F;routing.html&quot;&gt;read the docs for Routing&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Server running at: http:&amp;#x2F;&amp;#x2F;localhost:8080&amp;#x2F;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now you can click on the link and reach your created server.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;express&quot;&gt;express&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;guide&#x2F;routing.html&quot;&gt;Routing&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;expressjs.com&#x2F;en&#x2F;guide&#x2F;routing.html#response-methods&quot;&gt;Response Methods&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you use &lt;code&gt;express&lt;&#x2F;code&gt; or some libraries like &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;koa&quot;&gt;koa&lt;&#x2F;a&gt; or &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;sails&quot;&gt;sails&lt;&#x2F;a&gt;? Why do you use it?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Create A Simple Server Using The HTTP Module</title>
        <published>2019-08-31T00:00:00+00:00</published>
        <updated>2019-08-31T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-31/" type="text/html"/>
        <id>https://miku86.com/2019-08-31/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to create a &lt;em&gt;simple server&lt;&#x2F;em&gt; using the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;http.html&quot;&gt;HTTP module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import http module
const http = require(&amp;quot;http&amp;quot;);

&amp;#x2F;&amp;#x2F; server configuration
const HOST = &amp;quot;127.0.0.1&amp;quot;;
const PORT = 8080;

&amp;#x2F;&amp;#x2F; create the server
const server = http.createServer((req, res) =&amp;gt; {
  res.end(&amp;quot;Hello!&amp;quot;);
});

&amp;#x2F;&amp;#x2F; make the server listen to requests
server.listen(PORT, HOST, () =&amp;gt; {
  console.log(`Server running at: http:&amp;#x2F;&amp;#x2F;${HOST}:${PORT}&amp;#x2F;`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;&#x2F;strong&gt;: This is an &lt;em&gt;extremely simple server&lt;&#x2F;em&gt;. I would recommend you to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;http.html&quot;&gt;read the docs of the HTTP module&lt;&#x2F;a&gt;, especially how headers work and how to send them.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Server running at: http:&amp;#x2F;&amp;#x2F;127.0.0.1:8080&amp;#x2F;
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now you can click on the link and reach your created server.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;http.html&quot;&gt;HTTP module&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;docs&#x2F;guides&#x2F;anatomy-of-an-http-transaction&quot;&gt;Anatomy of an HTTP Transaction&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;http2.html&quot;&gt;HTTP&#x2F;2 module&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;https.html&quot;&gt;HTTPS module&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you use the native &lt;code&gt;HTTP&#x2F;HTTPS&lt;&#x2F;code&gt; module or some libraries like &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;express&quot;&gt;express&lt;&#x2F;a&gt;? Why do you use it?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Send An Email</title>
        <published>2019-08-30T00:00:00+00:00</published>
        <updated>2019-08-30T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-30/" type="text/html"/>
        <id>https://miku86.com/2019-08-30/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;We also know &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-get-external-packages-npm-56oj&quot;&gt;How to Get External Packages&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to send an email using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;nodemailer&quot;&gt;nodemailer&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import nodemailer (after npm install nodemailer)
const nodemailer = require(&amp;quot;nodemailer&amp;quot;);

&amp;#x2F;&amp;#x2F; config for mailserver and mail, input your data
const config = {
  mailserver: {
    host: &amp;quot;smtp.ethereal.email&amp;quot;,
    port: 587,
    secure: false,
    auth: {
      user: &amp;quot;yutfggtgifd7ixet@ethereal.email&amp;quot;,
      pass: &amp;quot;tX29P4QNadD7kAG7x5&amp;quot;,
    },
  },
  mail: {
    from: &amp;quot;foo@example.com&amp;quot;,
    to: &amp;quot;bar@example.com&amp;quot;,
    subject: &amp;quot;Hey&amp;quot;,
    text: &amp;quot;Testing Nodemailer&amp;quot;,
  },
};

const sendMail = async ({ mailserver, mail }) =&amp;gt; {
  &amp;#x2F;&amp;#x2F; create a nodemailer transporter using smtp
  let transporter = nodemailer.createTransport(mailserver);

  &amp;#x2F;&amp;#x2F; send mail using transporter
  let info = await transporter.sendMail(mail);

  console.log(`Preview: ${nodemailer.getTestMessageUrl(info)}`);
};

sendMail(config).catch(console.error);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: Nodemailer has a lot of available settings, therefore read &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodemailer.com&quot;&gt;the docs of nodemailer&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Preview: https:&amp;#x2F;&amp;#x2F;ethereal.email&amp;#x2F;message&amp;#x2F;XWk2jZDkEStePsCvXWk60Yf74VUAhgNZAAAACQqQo2lpzFsxaciWAqd9ZjY
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;nodemailer&quot;&gt;nodemailer on npm&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodemailer.com&quot;&gt;nodemailer docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodemailer.com&#x2F;smtp&quot;&gt;config mailserver&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodemailer.com&#x2F;message&quot;&gt;config mail&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What is your favorite way&#x2F;package to send mails in Node?&lt;&#x2F;li&gt;
&lt;li&gt;Do you automate some tasks with node emails?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Create Your Own Module</title>
        <published>2019-08-29T00:00:00+00:00</published>
        <updated>2019-08-29T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-29/" type="text/html"/>
        <id>https://miku86.com/2019-08-29/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to create our own &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;modules.html&quot;&gt;module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;logger.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch logger.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; the function should get a message type and a message
function logger(type, message) {
  let format;

  &amp;#x2F;&amp;#x2F; different message for different message type
  switch (type) {
    case &amp;quot;error&amp;quot;:
      format = `[ERROR] ${message}`;
      break;
    case &amp;quot;success&amp;quot;:
      format = `[SUCCESS] ${message}`;
      break;
    default:
      format = `${message}`;
      break;
  }

  console.log(format);
}

&amp;#x2F;&amp;#x2F; export the function using object property shorthand syntax
&amp;#x2F;&amp;#x2F; to rename, use &amp;quot;newName: logger&amp;quot;
module.exports = {
  logger,
};
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: For the sake of simplicity, this example is very lightweight, has no error&#x2F;edge-case handling (e.g. no type), no separate file for the message types, no colors etc.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;write-a-second-simple-script&quot;&gt;Write a second simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import the exported logger property
const { logger } = require(&amp;quot;.&amp;#x2F;logger.js&amp;quot;);

&amp;#x2F;&amp;#x2F; use the function
logger(&amp;quot;error&amp;quot;, &amp;quot;This is an error message.&amp;quot;);
logger(&amp;quot;success&amp;quot;, &amp;quot;This is a success message&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre&gt;&lt;code&gt;[ERROR] This is an error message.
[SUCCESS] This is a success message.
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Q: What happens, when you forget to add a &lt;code&gt;type&lt;&#x2F;code&gt;? How can you solve this?&lt;&#x2F;li&gt;
&lt;li&gt;Q: How can you improve this example by separating the message types into a constant?&lt;&#x2F;li&gt;
&lt;li&gt;Q: How can you improve this example by using an object as parameter instead of two strings?&lt;&#x2F;li&gt;
&lt;li&gt;Q: Do you need some additional error handling? (=&amp;gt; Docs)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;modules.html&quot;&gt;Modules&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;modules.html#modules_module_exports&quot;&gt;module.exports&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;modules.html#modules_exports_shortcut&quot;&gt;exports shortcut&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What is your favorite self-written module, that improves your developer life?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Colorize Text</title>
        <published>2019-08-28T00:00:00+00:00</published>
        <updated>2019-08-28T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-28/" type="text/html"/>
        <id>https://miku86.com/2019-08-28/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;We also know &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-get-external-packages-npm-56oj&quot;&gt;How to Get External Packages&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to colorize text using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;chalk&quot;&gt;chalk&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import chalk
const chalk = require(&amp;quot;chalk&amp;quot;);

&amp;#x2F;&amp;#x2F; Example 1: inline styling, blue background and underline
console.log(chalk.bgBlue.underline(&amp;quot;Example 1&amp;quot;));

&amp;#x2F;&amp;#x2F; Example 2: create reusable style
const success = chalk.bgGreen.black.underline;
console.log(success(&amp;quot;Example 2&amp;quot;));

&amp;#x2F;&amp;#x2F; Example 3: you can do a lot of stuff, e.g. using hex values and template literals
const customize = chalk.hex(&amp;quot;#B4DA55&amp;quot;).bold;
console.log(`This is ${customize(&amp;quot;Example 3&amp;quot;)}.`);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: Chalk has a lot of available styles, read &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;chalk#styles&quot;&gt;the docs of chalk&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;https:&#x2F;&#x2F;thepracticaldev.s3.amazonaws.com&#x2F;i&#x2F;sbx0oj2ipy33i1oq5jqy.png&quot; alt=&quot;Alt Text&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;chalk&quot;&gt;chalk on npm&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;chalk#usage&quot;&gt;chalk usage on npm&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What is your favorite way&#x2F;package to colorize text in Node? Why do you use it?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Write Data As JSON To Your Machine</title>
        <published>2019-08-27T00:00:00+00:00</published>
        <updated>2019-08-27T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-27/" type="text/html"/>
        <id>https://miku86.com/2019-08-27/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Last time, we learned &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-read-a-json-file-from-your-machine-1jg9&quot;&gt;how to read data&lt;&#x2F;a&gt; from our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to write data as JSON to our machine using the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html&quot;&gt;File System (FS) module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);

const FILE_NAME = &amp;quot;data-write.json&amp;quot;;
const NEW_DATA = [{ id: 2, name: &amp;quot;Max&amp;quot; }];

const writeFileAsync = (newData) =&amp;gt; {
  const stringifiedData = JSON.stringify(newData);

  fs.writeFile(FILE_NAME, stringifiedData, (error) =&amp;gt; {
    if (error) {
      console.log(&amp;quot;Async Write: NOT successful!&amp;quot;);
      console.log(error);
    } else {
      console.log(&amp;quot;Async Write: successful!&amp;quot;);
      console.log(stringifiedData);
    }
  });
};

writeFileAsync(NEW_DATA);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: We are using the async &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_fs_writefile_file_data_options_callback&quot;&gt;&lt;code&gt;writeFile&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; function to write data, because we don&#x27;t want to block other tasks. You can also write data synchronously using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_fs_writefilesync_file_data_options&quot;&gt;&lt;code&gt;writeFileSync&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, but this could block some other tasks.&lt;&#x2F;p&gt;
&lt;p&gt;Note: You can do a lot of stuff with the File System module, therefore &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_file_system_flags&quot;&gt;read the docs of the FS module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;every-line-explained&quot;&gt;Every line explained&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import the file system module
const fs = require(&amp;quot;fs&amp;quot;);

&amp;#x2F;&amp;#x2F; save the file name of our data in a variable (increase readability)
const FILE_NAME = &amp;quot;data-write.json&amp;quot;;

&amp;#x2F;&amp;#x2F; save the new data in a variable (increase readability)
const NEW_DATA = [{ id: 2, name: &amp;quot;Max&amp;quot; }];

const writeFileAsync = (newData) =&amp;gt; {
  &amp;#x2F;&amp;#x2F; convert the  JavaScript values to a JSON string
  const stringifiedData = JSON.stringify(newData);

  &amp;#x2F;&amp;#x2F; run async function to write file
  fs.writeFile(FILE_NAME, stringifiedData, (error) =&amp;gt; {
    if (error) {
      &amp;#x2F;&amp;#x2F; if there is an error, print it
      console.log(&amp;quot;Async Write: NOT successful!&amp;quot;);
      console.log(error);
    } else {
      console.log(&amp;quot;Async Write: successful!&amp;quot;);
      console.log(stringifiedData);
    }
  });
};

&amp;#x2F;&amp;#x2F; run the function
writeFileAsync(NEW_DATA);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: We are using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;JavaScript&#x2F;Reference&#x2F;Global_Objects&#x2F;JSON&#x2F;stringify&quot;&gt;&lt;code&gt;JSON.stringify()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; to convert the JavaScript values to a JSON string.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Async Write: successful!
[{&amp;quot;id&amp;quot;:2,&amp;quot;name&amp;quot;:&amp;quot;Max&amp;quot;}]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Q: What happens, when &lt;code&gt;data-write.json&lt;&#x2F;code&gt; already exists?&lt;&#x2F;li&gt;
&lt;li&gt;Q: How can we tackle this issue?&lt;&#x2F;li&gt;
&lt;li&gt;Q: Do we need some additional error handling? (=&amp;gt; Docs)&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html&quot;&gt;File System module&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_file_system_flags&quot;&gt;File System Flags&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Did you ever use the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_fs_promises_api&quot;&gt;&lt;code&gt;fs Promises API&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, that uses Promises instead of Callbacks?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Read A JSON File From Your Machine</title>
        <published>2019-08-26T00:00:00+00:00</published>
        <updated>2019-08-26T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-26/" type="text/html"/>
        <id>https://miku86.com/2019-08-26/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to read a JSON file from our machine using the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html&quot;&gt;File System (FS) module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;create-a-file-with-some-data&quot;&gt;Create a file with some data&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;data-read.json&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch data-read.json
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add some JSON data into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;json&quot; class=&quot;language-json &quot;&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;[{ &amp;quot;id&amp;quot;: 1, &amp;quot;name&amp;quot;: &amp;quot;miku86&amp;quot; }]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const fs = require(&amp;quot;fs&amp;quot;);

const FILE_NAME = &amp;quot;data-read.json&amp;quot;;

const readFileAsync = () =&amp;gt; {
  fs.readFile(FILE_NAME, (error, data) =&amp;gt; {
    console.log(&amp;quot;Async Read: starting...&amp;quot;);
    if (error) {
      console.log(&amp;quot;Async Read: NOT successful!&amp;quot;);
      console.log(error);
    } else {
      try {
        const dataJson = JSON.parse(data);
        console.log(&amp;quot;Async Read: successful!&amp;quot;);
        console.log(dataJson);
      } catch (error) {
        console.log(error);
      }
    }
  });
};

readFileAsync();
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: We are using the async &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_fs_readfile_path_options_callback&quot;&gt;&lt;code&gt;readFile&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; function to read data, because we don&#x27;t want to block other tasks. You can also read data synchronous using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_fs_readfilesync_path_options&quot;&gt;&lt;code&gt;readFileSync&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, but this could block some other tasks.&lt;&#x2F;p&gt;
&lt;p&gt;Note: You can do a lot of stuff with the File System module, therefore &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_file_system_flags&quot;&gt;read the docs of the FS module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;every-line-explained&quot;&gt;Every line explained&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import the file system module
const fs = require(&amp;quot;fs&amp;quot;);

&amp;#x2F;&amp;#x2F; save the file name of our data in a variable (increase readability)
const FILE_NAME = &amp;quot;data-read.json&amp;quot;;

const readFileAsync = () =&amp;gt; {
  &amp;#x2F;&amp;#x2F; run async function to read file
  fs.readFile(FILE_NAME, (error, data) =&amp;gt; {
    console.log(&amp;quot;Async Read: starting...&amp;quot;);

    if (error) {
      &amp;#x2F;&amp;#x2F; if there is an error, print it
      console.log(&amp;quot;Async Read: NOT successful!&amp;quot;);
      console.log(error);
    } else {
      try {
        &amp;#x2F;&amp;#x2F; try to parse the JSON data
        const dataJson = JSON.parse(data);
        console.log(&amp;quot;Async Read: successful!&amp;quot;);
        console.log(dataJson);
      } catch (error) {
        &amp;#x2F;&amp;#x2F; else print an error (e.g. JSON was invalid)
        console.log(error);
      }
    }
  });
};

&amp;#x2F;&amp;#x2F; run the function
readFileAsync();
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Async Read: starting...
Async Read: successful!
[ { id: 1, name: &amp;#x27;miku86&amp;#x27; } ]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html&quot;&gt;File System module&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_file_system_flags&quot;&gt;File System Flags&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Did you ever use the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;fs.html#fs_fs_promises_api&quot;&gt;&lt;code&gt;fs Promises API&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, that uses Promises instead of Callbacks?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Use The OS Module</title>
        <published>2019-08-25T00:00:00+00:00</published>
        <updated>2019-08-25T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-25/" type="text/html"/>
        <id>https://miku86.com/2019-08-25/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to get information about the operating system by using the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;os.html&quot;&gt;OS module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const { platform, arch, release, totalmem, freemem } = require(&amp;quot;os&amp;quot;);

console.log(`Your Operating System: ${release()} ${platform()} ${arch()}`);
console.log(
  `${((freemem() &amp;#x2F; totalmem()) * 100).toFixed(2)} % of your RAM is free.`
);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: I use the most used url properties to decrease the complexity of this simple example. To see all the available properties, read &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;os.html#os_os&quot;&gt;the docs of the OS module&lt;&#x2F;a&gt;. There is a lot of cool stuff.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;every-line-explained&quot;&gt;Every line explained&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;*
  import the os module &amp;amp; destructure the desired properties&amp;#x2F;functions
  similar to:
  const os = require(&amp;#x27;os&amp;#x27;);
  const { platform, arch, release, totalmem, freemem } = os;
*&amp;#x2F;

const { platform, arch, release, totalmem, freemem } = require(&amp;quot;os&amp;quot;);

&amp;#x2F;&amp;#x2F; log some information about the operating system
console.log(`Your Operating System: ${release()} ${platform()} ${arch()}`);

&amp;#x2F;&amp;#x2F; log some information about the memory (ram) (number is rounded to two decimals)
console.log(
  `${((freemem() &amp;#x2F; totalmem()) * 100).toFixed(2)} % of your RAM is free.`
);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;Your Operating System: 5.2.9-arch1-1-ARCH linux x64
18.63 % of your RAM is free.

&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;os.html&quot;&gt;OS module&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;os.html#os_os&quot;&gt;OS properties overview&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you have an interesting idea, what we could create with this module?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Use The URL Module</title>
        <published>2019-08-24T00:00:00+00:00</published>
        <updated>2019-08-24T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-24/" type="text/html"/>
        <id>https://miku86.com/2019-08-24/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;We also know &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;nodejs-how-to-run-scripts-from-the-terminal-use-arguments-2olm&quot;&gt;how to use commandline arguments&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to learn how to process an &lt;code&gt;url&lt;&#x2F;code&gt; from the commandline by using the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html&quot;&gt;URL module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;const url = require(&amp;quot;url&amp;quot;);

const myUrl = process.argv[2];

if (myUrl) {
  const { href, host, pathname, protocol } = new URL(myUrl);

  console.log(`The HREF is: ${href}`);
  console.log(`The Protocol is: ${protocol}`);
  console.log(`The Host is: ${host}`);
  console.log(`The Pathname is: ${pathname}`);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: I use the most used url properties to decrease the complexity of this simple example. To see all the available properties, read &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html#url_url_strings_and_url_objects&quot;&gt;the docs of the URL module&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;every-line-explained&quot;&gt;Every line explained&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; import the url module
const url = require(&amp;quot;url&amp;quot;);

&amp;#x2F;&amp;#x2F; read the third argument (= the url ) &amp;amp; save it into a variable
const myUrl = process.argv[2];

&amp;#x2F;&amp;#x2F; only run this block if the user inputs a third argument
if (myUrl) {
  &amp;#x2F;&amp;#x2F; destructure these specific properties from the URL
  const { href, host, pathname, protocol } = new URL(myUrl);

  &amp;#x2F;&amp;#x2F; log the destructured properties
  console.log(`The Href is: ${href}`);
  console.log(`The Protocol is: ${protocol}`);
  console.log(`The Host is: ${host}`);
  console.log(`The Pathname is: ${pathname}`);
}
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Sometimes you can see the usage of &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost&quot;&gt;url.parse()&lt;&#x2F;a&gt; from the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html#url_legacy_url_api&quot;&gt;Legacy URL API&lt;&#x2F;a&gt;. The Legacy URL API is deprecated, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html#url_legacy_url_api&quot;&gt;don&#x27;t use &lt;code&gt;url.parse()&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;, use &lt;code&gt;new URL()&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js https:&amp;#x2F;&amp;#x2F;miku86.com&amp;#x2F;articles
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;The Href is: https:&amp;#x2F;&amp;#x2F;miku86.com&amp;#x2F;articles
The Protocol is: https:
The Host is: miku86.com
The Pathname is: &amp;#x2F;articles
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html&quot;&gt;URL module&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html#url_url_strings_and_url_objects&quot;&gt;URL properties overview&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;url.html#url_class_url&quot;&gt;URL properties explained&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you use the native &lt;code&gt;URL module&lt;&#x2F;code&gt; or some libraries like &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;query-string&quot;&gt;query-string&lt;&#x2F;a&gt;? Why do you use it?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Talk&#x2F;Answer To The Terminal</title>
        <published>2019-08-23T00:00:00+00:00</published>
        <updated>2019-08-23T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-23/" type="text/html"/>
        <id>https://miku86.com/2019-08-23/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to write a simple script, run it from the terminal &amp;amp; talk&#x2F;answer to the terminal&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add this JavaScript code into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;process.stdout.write(&amp;quot;What&amp;#x27;s your name?\n&amp;quot;);

process.stdin.on(&amp;quot;readable&amp;quot;, () =&amp;gt; {
  const userInput = process.stdin.read();
  process.stdout.write(`Your Input was: ${userInput}`);
});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Note: I removed all &amp;quot;unnecessary&amp;quot; stuff from the documentation to decrease the complexity of this simple example.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;every-line-decoded&quot;&gt;Every line decoded&lt;&#x2F;h2&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; writes something to the stdout (your terminal), including a newline at the end
process.stdout.write(&amp;quot;What&amp;#x27;s your name?\n&amp;quot;);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;code&gt;Console.log()&lt;&#x2F;code&gt; uses &lt;code&gt;stdout&lt;&#x2F;code&gt; &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;console.html#console_console_log_data_args&quot;&gt;under the hood&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; if a specific event (here: a readable stream) happens, then run this  callback
process.stdin.on(&amp;#x27;readable&amp;#x27;, () =&amp;gt; {...});
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;stream.html#stream_readable_streams&quot;&gt;Documentation for readable stream&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; read data from the stream &amp;amp; save it into a variable
const userInput = process.stdin.read();
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&amp;#x2F;&amp;#x2F; writes something to the stdout
process.stdout.write(`Your Input was: ${userInput}`);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Result:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;What`s your name?
miku86
Your Input was: miku86
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you use the native &lt;code&gt;process.stdin&lt;&#x2F;code&gt; or some libraries like &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;inquirer&quot;&gt;&lt;code&gt;inquirer&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; or &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;prompts&quot;&gt;&lt;code&gt;prompts&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;? Why?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How To Run Scripts From The Terminal &amp; Use Arguments</title>
        <published>2019-08-22T00:00:00+00:00</published>
        <updated>2019-08-22T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-22/" type="text/html"/>
        <id>https://miku86.com/2019-08-22/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Now we want to write a simple script, run it from the terminal &amp;amp; use some commandline arguments.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;write-a-simple-script&quot;&gt;Write a simple script&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Open your terminal&lt;&#x2F;li&gt;
&lt;li&gt;Create a file named &lt;code&gt;index.js&lt;&#x2F;code&gt;:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;touch index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Add &lt;code&gt;console.log(&#x27;Hello&#x27;)&lt;&#x2F;code&gt; into it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;echo &amp;quot;console.log(&amp;#x27;Hello&amp;#x27;)&amp;quot; &amp;gt; index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;run-it-from-the-terminal&quot;&gt;Run it from the terminal&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Run it:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;use-commandline-arguments&quot;&gt;Use commandline arguments&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Update &lt;code&gt;index.js&lt;&#x2F;code&gt; to use the commandline arguments and print them:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;echo &amp;quot;const args = process.argv&amp;quot; &amp;gt; index.js
echo &amp;quot;console.log(args)&amp;quot; &amp;gt;&amp;gt; index.js
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;Run it with an argument:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;node index.js miku86
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;ul&gt;
&lt;li&gt;We are seeing an array with 3 elements:&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;pre data-lang=&quot;bash&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;[
&amp;#x27;&amp;#x2F;usr&amp;#x2F;bin&amp;#x2F;node&amp;#x27;,
&amp;#x27;&amp;#x2F;home&amp;#x2F;miku86&amp;#x2F;index.js&amp;#x27;,
&amp;#x27;miku86&amp;#x27;
]
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;args[0] is the path to the executable file,
args[1] is the path to the executed file,
args[2] is the additional commandline argument from step 2.&lt;&#x2F;p&gt;
&lt;p&gt;So if we want to use our additional commandline argument,
we can use it like this in a JavaScript file:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;console.log(args[2]);
&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;api&#x2F;process.html#process_process_argv&quot;&gt;Node process.argv documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Do you use the native &lt;code&gt;process&lt;&#x2F;code&gt; or some libraries like &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;yargs&quot;&gt;&lt;code&gt;yargs&lt;&#x2F;code&gt;&lt;&#x2F;a&gt;? Why?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: How to Get External Packages &#x2F; npm</title>
        <published>2019-08-21T00:00:00+00:00</published>
        <updated>2019-08-21T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-21/" type="text/html"/>
        <id>https://miku86.com/2019-08-21/</id>
        
        <content type="html">&lt;h2 id=&quot;intro&quot;&gt;Intro&lt;&#x2F;h2&gt;
&lt;p&gt;So we &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt; on our machine.&lt;&#x2F;p&gt;
&lt;p&gt;Because there is already a lot of code out there in the internet, we can use other peoples&#x27; code so we do not have to reinvent the wheel to solve problems, that are already solved.&lt;&#x2F;p&gt;
&lt;p&gt;In order to easily get solutions from other people, we can use a tool called npm.&lt;&#x2F;p&gt;
&lt;p&gt;This will be a short intro to npm with the most used commands.
If you want to learn some advanced concepts, read the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;&quot;&gt;npm documentation&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;what-is-npm&quot;&gt;What is npm?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;npm is a package manager for JavaScript packages&lt;&#x2F;li&gt;
&lt;li&gt;npm is the world’s largest software registry&lt;&#x2F;li&gt;
&lt;li&gt;npm comes with the NodeJS installer, so if you already &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt;, you already have npm on your machine&lt;&#x2F;li&gt;
&lt;li&gt;you download packages with the command line interface&lt;&#x2F;li&gt;
&lt;li&gt;you get information about packages through the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;&quot;&gt;npm website&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;how-to-install-npm&quot;&gt;How To Install npm?&lt;&#x2F;h2&gt;
&lt;p&gt;If you already &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;miku86.com&#x2F;blog&#x2F;what-is-nodejs-how-to-install-it-1900&quot;&gt;installed NodeJS&lt;&#x2F;a&gt;, you already have npm on your machine.&lt;&#x2F;p&gt;
&lt;p&gt;To check, if npm is installed:
&lt;code&gt;npm --version&lt;&#x2F;code&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;how-to-get-external-packages&quot;&gt;How to Get External Packages?&lt;&#x2F;h2&gt;
&lt;p&gt;Most of the time, you want to use packages project-wise.&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Initialize a npm project in an existing folder: &lt;code&gt;npm init&lt;&#x2F;code&gt;. This will create a &lt;code&gt;package.json&lt;&#x2F;code&gt; file, where all your settings will be saved.&lt;&#x2F;li&gt;
&lt;li&gt;Answer all questions like &lt;code&gt;package name&lt;&#x2F;code&gt;, &lt;code&gt;version&lt;&#x2F;code&gt; etc. You can read about the correct answers &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;files&#x2F;package.json&quot;&gt;here&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Go to &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&quot;&gt;npm&lt;&#x2F;a&gt; and search for a package, e.g. &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;search?q=text%20color&quot;&gt;&amp;quot;text color&amp;quot;&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;You will get a list of matching packages, click on the link to the package and read the documentation, e.g. the package &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;chalk&quot;&gt;&amp;quot;chalk&amp;quot;&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Most of the time, the documentation will give you an appropriate &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;chalk#install&quot;&gt;command to install the package&lt;&#x2F;a&gt;, e.g. &lt;code&gt;npm install chalk&lt;&#x2F;code&gt;. If you want to see all the possibilities how to &lt;code&gt;npm install&lt;&#x2F;code&gt; a package, read &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;cli&#x2F;install&quot;&gt;the npm install docs&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;The package gets downloaded, you have to wait for some time.&lt;&#x2F;li&gt;
&lt;li&gt;Read the package documentation to learn &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;chalk#usage&quot;&gt;how to use the package&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;additional-commands&quot;&gt;Additional Commands&lt;&#x2F;h2&gt;
&lt;p&gt;If you want to learn additional commands, e.g. uninstall a package, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;cli-documentation&#x2F;&quot;&gt;read the documentation&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;about-npm&#x2F;&quot;&gt;npm Homepage&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;cli&#x2F;install.html&quot;&gt;npm install Docs&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Npm_(software)&quot;&gt;npm on Wikipedia&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;questions&quot;&gt;Questions&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;What beginner&#x27;s problem would you have liked to have solved here as well?&lt;&#x2F;li&gt;
&lt;li&gt;Are the instructions clear, understandable and comprehensible?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>NodeJS: What is it &amp; How To Install it</title>
        <published>2019-08-20T00:00:00+00:00</published>
        <updated>2019-08-20T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-20/" type="text/html"/>
        <id>https://miku86.com/2019-08-20/</id>
        
        <content type="html">&lt;h2 id=&quot;what-is-nodejs&quot;&gt;What is NodeJS?&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;a run-time environment that executes JavaScript code outside of a browser&lt;&#x2F;li&gt;
&lt;li&gt;has an event-driven architecture capable of asynchronous I&#x2F;O, therefore used in many real-time web applications, e.g. chat applications&lt;&#x2F;li&gt;
&lt;li&gt;two main use cases: server-side scripts &amp;amp; command line tools&lt;&#x2F;li&gt;
&lt;li&gt;no need to learn two languages to write fullstack applications&lt;&#x2F;li&gt;
&lt;li&gt;has a &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;about-npm&#x2F;&quot;&gt;big ecosystem&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;how-to-install-it&quot;&gt;How To Install it?&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;windows&quot;&gt;Windows&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Go to the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;download&#x2F;current&#x2F;&quot;&gt;NodeJS download page&lt;&#x2F;a&gt; and click on &lt;code&gt;Windows Installer&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Go through the Installer&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;macos&quot;&gt;macOS&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;Go to the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;download&#x2F;current&#x2F;&quot;&gt;NodeJS download page&lt;&#x2F;a&gt; and click on &lt;code&gt;macOS Installer&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;Go through the Installer&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;ubuntu&quot;&gt;Ubuntu&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;curl -sL https:&#x2F;&#x2F;deb.nodesource.com&#x2F;setup_12.x | sudo -E bash -&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;sudo apt-get install -y nodejs&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;arch&quot;&gt;Arch&lt;&#x2F;h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;pacman -S nodejs npm&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;hr &#x2F;&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further Reading&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;&quot;&gt;NodeJS Homepage&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;nodejs.org&#x2F;en&#x2F;docs&#x2F;&quot;&gt;NodeJS Documentation&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Node.js&quot;&gt;NodeJS on Wikipedia&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.npmjs.com&#x2F;about-npm&#x2F;&quot;&gt;npm&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>30 Day Challenge: Write one Post per Day</title>
        <published>2019-08-19T00:00:00+00:00</published>
        <updated>2019-08-19T00:00:00+00:00</updated>
        <author>
          <name>Unknown</name>
        </author>
        <link rel="alternate" href="https://miku86.com/2019-08-19/" type="text/html"/>
        <id>https://miku86.com/2019-08-19/</id>
        
        <content type="html">&lt;p&gt;I start my &amp;quot;30 Day Challenge: Write one Post per Day&amp;quot;.&lt;&#x2F;p&gt;
&lt;p&gt;My Why:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I want to strengthen my publishing habits&lt;&#x2F;li&gt;
&lt;li&gt;I want to tackle my fear of publishing&lt;&#x2F;li&gt;
&lt;li&gt;I want to share my knowledge&lt;&#x2F;li&gt;
&lt;li&gt;I want to strengthen my writing skills&lt;&#x2F;li&gt;
&lt;li&gt;I want to benefit from social accountability&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Rules:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;published between 0.00 - 23.59, UTC +2&lt;&#x2F;li&gt;
&lt;li&gt;at least 1.000 characters&lt;&#x2F;li&gt;
&lt;li&gt;no copy of an old post&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Questions:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What are your experiences with these kind of challenges?&lt;&#x2F;li&gt;
&lt;li&gt;What are your tips to improve my challenge?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
</feed>
