<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Farhan Yahya</title>
    <description>The latest articles on DEV Community by Farhan Yahya (@dochan).</description>
    <link>https://dev.to/dochan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F166111%2F37993742-a415-407f-978e-24e3a2e2627d.png</url>
      <title>DEV Community: Farhan Yahya</title>
      <link>https://dev.to/dochan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dochan"/>
    <language>en</language>
    <item>
      <title>xtensio - a new framework for browser extension development</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Sat, 19 Aug 2023 02:29:16 +0000</pubDate>
      <link>https://dev.to/dochan/xtensio-a-new-framework-for-browser-extension-development-1nb2</link>
      <guid>https://dev.to/dochan/xtensio-a-new-framework-for-browser-extension-development-1nb2</guid>
      <description>&lt;p&gt;Are you curios? Check it out. &lt;br&gt;
&lt;a href="https://github.com/doc-han/xtensio"&gt;https://github.com/doc-han/xtensio&lt;/a&gt;&lt;/p&gt;

</description>
      <category>extensions</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Tech interview &amp; Social media presence 😡😡😡</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Wed, 21 Jul 2021 08:55:12 +0000</pubDate>
      <link>https://dev.to/dochan/tech-interview-social-media-presence-5c60</link>
      <guid>https://dev.to/dochan/tech-interview-social-media-presence-5c60</guid>
      <description>&lt;p&gt;Like seriously why is everyone looking for social media presence along side resumes these days? &lt;br&gt;
Do recruiters depend on it that much?&lt;br&gt;
Example: I'm not a social media person, I love one-to-one interactions with people in my life, Quit using Facebook in 2015 which was the only social thing I used then. &lt;br&gt;
Currently I only use WhatsApp which suits my definition of connecting with people. &lt;/p&gt;

&lt;p&gt;But OMG, every job application page now has a required field for social media handles.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Can you check for prime numbers? - Primality Test</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Sun, 12 Jul 2020 11:08:29 +0000</pubDate>
      <link>https://dev.to/dochan/can-you-check-for-prime-numbers-primality-test-113c</link>
      <guid>https://dev.to/dochan/can-you-check-for-prime-numbers-primality-test-113c</guid>
      <description>&lt;p&gt;This is one of the simple programs most developers really don't know how to go about. Just imagine getting such this question wrong at a coding interview while you aced all the language specific questions. That will be so sad.&lt;/p&gt;

&lt;p&gt;In this post we'll look at how to check whether a value is prime or not using a primality test known as &lt;strong&gt;TRIAL DIVISION&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  LITTLE EXPLANATION
&lt;/h2&gt;

&lt;p&gt;Now, let's look at how one might go about this problem. Since a prime number is a number with just two divisors (1 and the number itself), a way to solve this problem is to try dividing the number by values between 1 and itself. If none divides perfectly then it's a prime number else it isn't. Hence, the code below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;isPrime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;But guess what? the downside of this code is when it actually finds a prime number. Because to find a prime number the for loop has to run n-2 times. So let's say you are to check whether &lt;strong&gt;13441&lt;/strong&gt; is a prime number, then that mean we need &lt;strong&gt;13439&lt;/strong&gt; iterations which is too much and what if we are to check for 10&lt;sup&gt;6&lt;/sup&gt; numbers? that's lot's of time and computing power. &lt;strong&gt;Hence, we have a nice way of cutting off some of the work.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TRIAL DIVISION
&lt;/h2&gt;

&lt;p&gt;With this method, we use a simple mathematical analysis to cut off most of the work that is to be done.&lt;/p&gt;

&lt;p&gt;The idea is that: For any composite number(a composite number is the opposite of a prime number) the first divisor apart from 1 can be found between 1 and root of n (where n is the number to be tested).&lt;br&gt;
eg. checking whether 100 is prime.&lt;br&gt;
numbers between 1 and root(100) are 2,3,4,5,6,7,8,9&lt;br&gt;
and fortunately 2 is a divisor of 100. &lt;br&gt;
This method reduces the number of iterations exponentially making our code look like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;isPrime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;// difference on this line i*i&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So the logic is to iterate from 2 to root(n). &lt;br&gt;
hence the condition &lt;strong&gt;i&amp;lt;=root(n)&lt;/strong&gt;, &lt;br&gt;
squaring both sides will give the condition &lt;strong&gt;i*i&amp;lt;=n&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And with this, to check whether &lt;strong&gt;13441&lt;/strong&gt; is prime we only iterate &lt;strong&gt;115&lt;/strong&gt; times instead of &lt;strong&gt;13439&lt;/strong&gt; times.&lt;/p&gt;

&lt;p&gt;Hope you learnt something today. Thanks&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>codenewbie</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to merge two Objects or Arrays in JavaScript</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Thu, 18 Jun 2020 06:57:09 +0000</pubDate>
      <link>https://dev.to/dochan/how-to-merge-two-objects-or-arrays-in-javascript-3i6p</link>
      <guid>https://dev.to/dochan/how-to-merge-two-objects-or-arrays-in-javascript-3i6p</guid>
      <description>&lt;p&gt;So for a while now I've know the spread operator in JavaScript. I have been using it for while now but I never knew it worked for objects too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merging two Arrays
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Merging two Objects
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Han&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;98&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// output: {name: 'Han', age: 98}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I hope you also know now. Thanks for reading!&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Is AI really intelligent?</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Tue, 05 May 2020 18:01:22 +0000</pubDate>
      <link>https://dev.to/dochan/is-ai-really-intelligent-3d00</link>
      <guid>https://dev.to/dochan/is-ai-really-intelligent-3d00</guid>
      <description>&lt;p&gt;I'm a computer science student who started his journey in Machine Learning not long ago and as I kept moving on and studying some learning algorithms and many more this question came up to me. Is AI really intelligent?&lt;/p&gt;

&lt;h2&gt;
  
  
  What I think
&lt;/h2&gt;

&lt;p&gt;For me, I'll say AI isn't that smart. Everything we've done is a nice try but we've gotten nowhere making computers smart.&lt;/p&gt;

&lt;p&gt;AI to me is just an imitation game, why would I say this? You'll realize it more when you see some of the applications of AI in visual arts, music, and writing screenplays. It's unable to create but to imitate. It simply tries to find patterns in the data it's fed and the funny thing is that even if none exists it still finds you something.&lt;/p&gt;

&lt;h2&gt;
  
  
  The difference
&lt;/h2&gt;

&lt;p&gt;When a human is fed with different paintings from different painters, he/she studies their individual artistic styles and uses it as a guide to creating something new but what AI will do is to just combine these paintings for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  My definition of AI
&lt;/h2&gt;

&lt;p&gt;Using mathematical formulas to find patterns in data and giving out an output that falls within that same pattern. Which humans can also do the hard way.&lt;/p&gt;

&lt;p&gt;Hence, I'll say AI is cool but it's just an imitation game. What do you think?&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Simple image lazy loading using JQuery</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Fri, 24 Apr 2020 13:51:52 +0000</pubDate>
      <link>https://dev.to/dochan/simple-lazy-loading-using-jquery-1n10</link>
      <guid>https://dev.to/dochan/simple-lazy-loading-using-jquery-1n10</guid>
      <description>&lt;p&gt;Lazy loading is a technique where images are given a placeholder to be displayed while the actual image is loading in the background. The placeholder gets replaced with the actual image once it's done loading in the background.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
Below is a series of fully explained code on how to implement lazy loading&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set the src attribute of your image to be the placeholder image
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"placeholder.png"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Give your image tag an attribute &lt;strong&gt;ref-src&lt;/strong&gt; to with the url of the actual image you want to load
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"placeholder.png"&lt;/span&gt; &lt;span class="na"&gt;ref-src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.pixabay.com/photo/2019/12/30/14/13/snail-4729777_960_720.jpg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;write some javascript code to load the image in background and replace the placeholder after image has been loaded
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// selecting image element to be lazy loaded&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;elem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//retrieving url from ref-data attribute&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ref-data&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//creating a new image object&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;loadingImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;//this function is called when the image object&lt;/span&gt;
&lt;span class="c1"&gt;//is done loading it's image&lt;/span&gt;
&lt;span class="nx"&gt;loadingImage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="c1"&gt;//src attribute of elem is being replaced&lt;/span&gt;
    &lt;span class="c1"&gt;//with that of loadingImage because its done loading&lt;/span&gt;
    &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;//the url from elem has been assigned&lt;/span&gt;
&lt;span class="c1"&gt;//to the new image object for loading &lt;/span&gt;
&lt;span class="nx"&gt;loadingImage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;An with this code you've implemented lazy loading. These days most developers ignore the use of spinners as placeholders but rather prefer a grey looking shadow of the image.&lt;/p&gt;
&lt;h2&gt;
  
  
  Lazy loading all images on your site
&lt;/h2&gt;

&lt;p&gt;To lazy load all images on your website, I have this simple script for you to use. Try understanding the code below because it's very similar to the one above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;imgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;imgs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;loadImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;imgs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;loadImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ref-src&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;newImg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;newImg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;done loading&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;newImg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Voilà! all images on your site will be lazy loaded but remember to always put your placeholder in the src section and the image you want to load in the ref-src attribute like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"placeholder here"&lt;/span&gt; &lt;span class="na"&gt;ref-src=&lt;/span&gt;&lt;span class="s"&gt;"actual image here"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>jquery</category>
      <category>javascript</category>
      <category>html</category>
    </item>
    <item>
      <title>What is your first surprise in 2020?</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Wed, 08 Jan 2020 01:48:12 +0000</pubDate>
      <link>https://dev.to/dochan/what-is-your-first-surprise-in-2020-2f6m</link>
      <guid>https://dev.to/dochan/what-is-your-first-surprise-in-2020-2f6m</guid>
      <description>&lt;p&gt;I fell from a scooter today and I'm hurt. From face, fingers to legs. Not really severe but these fingers will surely type again. Alhamdulillah 😊&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>2020</category>
    </item>
    <item>
      <title>Binary Exponentiation</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Mon, 06 Jan 2020 10:01:31 +0000</pubDate>
      <link>https://dev.to/dochan/binary-exponentiation-5bfn</link>
      <guid>https://dev.to/dochan/binary-exponentiation-5bfn</guid>
      <description>&lt;p&gt;Binary exponentiation is a simple technique used to find the value for &lt;strong&gt;a&lt;sup&gt;n&lt;/sup&gt;&lt;/strong&gt; in O(logn) multiplications instead of the naive way which is O(n) multiplications. First, let's have a look at the naive way then this way.&lt;/p&gt;

&lt;h2&gt;
  
  
  The naive way
&lt;/h2&gt;

&lt;p&gt;From mathematics, &lt;strong&gt;a&lt;sup&gt;n&lt;/sup&gt;&lt;/strong&gt; is expressed as a multiplying itself n times. Hence a naive function for solving this will be like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="n"&gt;ans&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is quite simple but we will want to reduce the complexity of this function and that is where binary exponentiation comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  This way(Binary Exponentiation)
&lt;/h2&gt;

&lt;p&gt;In this method, the work is split into the binary representation of the exponent which reduces the computation to O(logn).&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;

&lt;p&gt;Naive: 3&lt;sup&gt;13&lt;/sup&gt; = 3 * 3 &lt;em&gt;...&lt;/em&gt; 3&lt;br&gt;
This way: 3&lt;sup&gt;13&lt;/sup&gt; = 3&lt;sup&gt;1101&lt;/sup&gt; = 3&lt;sup&gt;8&lt;/sup&gt; * 3&lt;sup&gt;4&lt;/sup&gt; * 3&lt;sup&gt;1&lt;/sup&gt;&lt;br&gt;
Implementing an algorithm for this is very simple. intead of looping n times we rather loop through the bits which is logn times. To get our solution, we then find the powers at which a bit is set just like the example above. Because we are using the binary presentation of n the power at a set bit will be the square of the previous set bit.&lt;br&gt;
That is:&lt;br&gt;
3&lt;sup&gt;1&lt;/sup&gt; = 3&lt;br&gt;
3&lt;sup&gt;2&lt;/sup&gt; = (3&lt;sup&gt;1&lt;/sup&gt;)&lt;sup&gt;2&lt;/sup&gt;&lt;br&gt;
3&lt;sup&gt;4&lt;/sup&gt; = (3&lt;sup&gt;2&lt;/sup&gt;)&lt;sup&gt;2&lt;/sup&gt;&lt;br&gt;
3&lt;sup&gt;8&lt;/sup&gt; = (3&lt;sup&gt;4&lt;/sup&gt;)&lt;sup&gt;2&lt;/sup&gt; ...&lt;/p&gt;

&lt;p&gt;So with this, we just find the product of the powers set in n.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code for this way
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
      &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above code computes in O(logn) which is better than the naive way which computes in O(n)&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>My only 2 plans for 2020 😖</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Sun, 05 Jan 2020 07:09:07 +0000</pubDate>
      <link>https://dev.to/dochan/my-only-2-plans-for-2020-4533</link>
      <guid>https://dev.to/dochan/my-only-2-plans-for-2020-4533</guid>
      <description>&lt;h2&gt;
  
  
  Everyone does it
&lt;/h2&gt;

&lt;p&gt;Whenever a year begins, one of the things you will hear here and there is a plan for the year or a todo list. This has been what I've been hearing from most of my friends but funny thing is that I never had one. All I knew was that it's a new year and life still goes on but some time ago I realized that this thing kind of help. Because I've been passing through the years just like that.&lt;/p&gt;

&lt;h2&gt;
  
  
  When I decided to do it
&lt;/h2&gt;

&lt;p&gt;Hence, I decided to start using a plan or a todo list and the year was 2019 😅😅.&lt;br&gt;
In December 2018 I has sat down and listed almost everything I wanted to do in 2019. It was an interesting list that I was very passionate about but I ended doing just one throughout the whole year. I touched some pieces but never completed them. So this year I came with a new strategy to make sure I'm able to complete the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I realized
&lt;/h2&gt;

&lt;p&gt;At the end of 2019, I realized something about me that might apply to you too.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;My list for 2019 was too long.&lt;/li&gt;
&lt;li&gt;It wasn't a year based todo list. It was what I wanted in life.&lt;/li&gt;
&lt;li&gt;I didn't weight the time for completion of each task before listing them.&lt;/li&gt;
&lt;li&gt;I always thought there is enough time in a year and even when In September I still see more time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And these are the reasons I'm going for just 2 plans this year. These plans are to help me in my subsequent plans.&lt;/p&gt;

&lt;h2&gt;
  
  
  My 2 plans
&lt;/h2&gt;

&lt;p&gt;These plans are very simple than you might have been guessing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I want to learn Machine learning(and all the math involved) and improve my Algorithms this year.&lt;/li&gt;
&lt;li&gt;I need a source of income.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The second point is very important to me because I'll be 20 this year and I still rely on my parents. Over here it's quite normal and happens all the time because of the high unemployment rate but I'm not okay with that. Hence this year, I''m going to try a variety of stuff from Youtube to small Saas software. I love open source tho&lt;/p&gt;

&lt;h5&gt;
  
  
  Please help with your ideas in the comment box
&lt;/h5&gt;

</description>
      <category>2020</category>
      <category>career</category>
      <category>yearinreview</category>
    </item>
    <item>
      <title>Did you nest your loop perfectly? Let's check it out.</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Thu, 31 Oct 2019 19:21:03 +0000</pubDate>
      <link>https://dev.to/dochan/did-you-nest-your-loop-perfectly-let-s-check-it-out-55ad</link>
      <guid>https://dev.to/dochan/did-you-nest-your-loop-perfectly-let-s-check-it-out-55ad</guid>
      <description>&lt;p&gt;Have you ever taught of how loops hurt the execution time of your code? if not then I think you should begin to worry about all these petty stuff when writing programs.&lt;/p&gt;

&lt;p&gt;Let's see how we can make your loop better. Let's say we have an &lt;strong&gt;array A of size 9 and an array B of size 7&lt;/strong&gt;, and our goal is to find the total sum when every single element in A is multiplied to every single element in B. Our code will be like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;//looping 9 elements&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;//looping 7 elements&lt;/span&gt;
        &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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



&lt;p&gt;Wait, let's analyze this loop. Let's assume that &lt;strong&gt;a single iteration takes a second&lt;/strong&gt;. Then that means that the outer loop which loops through array A(9 elements) will take 9s to run and the inner loop that loops through array B will take 7s to run. But because the inner loop is inside another loop, and the inner loop is called 9 times, the whole code will then take 9+(9x7) seconds to run. Meaning it takes our code 72s(1m 12s) to run.&lt;/p&gt;

&lt;h1&gt;
  
  
  How do we reduce the execution time?
&lt;/h1&gt;

&lt;p&gt;As simple as it is, let's just make sure to &lt;strong&gt;always nest the loop that iterates the most&lt;/strong&gt;. In the example above, instead of nesting the loop that goes through B, we would rather nest the loop that goes through A.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;// looping 7 elements&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt; &lt;span class="c1"&gt;//looping 9 elements&lt;/span&gt;
        &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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



&lt;p&gt;Then, our total time taken instead of being 9+(9x7) seconds will be 7+(7x9) seconds which is 70s(1m 10s).&lt;/p&gt;

&lt;p&gt;Hence time saved is 72s - 70s which is 2s. Imagine the time saved in computations with large array sizes. Hope you liked it&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>programming</category>
      <category>javascript</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Computer Science for all</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Fri, 20 Sep 2019 15:56:52 +0000</pubDate>
      <link>https://dev.to/dochan/computer-science-for-all-1eoo</link>
      <guid>https://dev.to/dochan/computer-science-for-all-1eoo</guid>
      <description>&lt;p&gt;Hi, I’m Han. &lt;/p&gt;

&lt;p&gt;I’m a computer science student and I will like to share what I learn at school in brief writings so that non-computer science developers or self-taught developers can also have a brief knowledge of some of the things we learn. &lt;/p&gt;

&lt;p&gt;I believe strongly that in order for one to understand something very well, he/she has to share the knowledge and also learn from others. Because of this, I joined a STEM education organization (&lt;a href="https://elite-education.org"&gt;EliTe education&lt;/a&gt;) way back in 2017 while I wasn’t yet in the University and it has helped me a lot.&lt;/p&gt;

&lt;p&gt;If you are interested in this journey, then tighten your seatbelts and let’s get going.&lt;/p&gt;

</description>
      <category>selftaught</category>
      <category>cs</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>In need of cool ideas</title>
      <dc:creator>Farhan Yahya</dc:creator>
      <pubDate>Thu, 19 Sep 2019 19:28:33 +0000</pubDate>
      <link>https://dev.to/dochan/in-need-of-cool-ideas-309l</link>
      <guid>https://dev.to/dochan/in-need-of-cool-ideas-309l</guid>
      <description>&lt;p&gt;I was walking down the stairs when my computer science department president stopped me and asked me to help him come up with cool ideas on programs or events for the semester. Our department is very boring and we want to make it feel as it's supposed to. Please I need suggestions and I appreciate all your contributions. THANKS&lt;/p&gt;

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