<?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: Martins Olumide</title>
    <description>The latest articles on DEV Community by Martins Olumide (@martinsolumide8).</description>
    <link>https://dev.to/martinsolumide8</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%2F1120825%2F5c5c750a-f3de-4ab3-a792-6498bbb08b2c.jpg</url>
      <title>DEV Community: Martins Olumide</title>
      <link>https://dev.to/martinsolumide8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/martinsolumide8"/>
    <language>en</language>
    <item>
      <title>How to use Web Worker in React with TypeScript</title>
      <dc:creator>Martins Olumide</dc:creator>
      <pubDate>Fri, 05 Jan 2024 20:02:06 +0000</pubDate>
      <link>https://dev.to/martinsolumide8/how-to-use-web-worker-in-react-with-typescript-4o79</link>
      <guid>https://dev.to/martinsolumide8/how-to-use-web-worker-in-react-with-typescript-4o79</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What are web workers&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prerequisites&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Initializing a project (VITE)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connecting the dots&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wrapping up&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are web workers
&lt;/h2&gt;

&lt;p&gt;According to MDN, Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering with the user interface. In addition, they can make network requests using the fetch() or XMLHttpRequest APIs. Once created, a worker can send messages to the JavaScript code that created it by posting messages to an event handler specified by that code (and vice versa).&lt;/p&gt;

&lt;p&gt;JavaScript as we all know is single-threaded I.E it can only execute only one thing at a time, it simple cannot multi-task like other languages out there. So, the Idea behind web worker is to aid or acts as an auxillary thread executer, taking the load off the Main thread. In some situations, we might want to fetch some resources that takes time to respond or perform some CPU intensive task that may cause the UI to hang or freeze, that's where Web Workers comes in. We take such Task or Computations and execute them in Background thread away from the main thread.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;Make sure you have a React project created, either CRA or VITE anyone. If you can't create one, follow this step. I'll be using VITE.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initializing a project (VITE)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Make sure you have NODE installed&lt;/span&gt;
&lt;span class="c1"&gt;//In your terminal, type this&lt;/span&gt;

&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt; &lt;span class="nx"&gt;vite&lt;/span&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;latest&lt;/span&gt;

&lt;span class="cm"&gt;/**This will bring a prompt telling you to name your project folder, after typing a name, press

Enter, then you'll be asked what framework (Choose React obviously), and choose TypeScript if

you want. After that, your project is all set and we can begin writing code.**/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Connecting the dots
&lt;/h2&gt;

&lt;p&gt;So now, after installations you should create a Worker folder (not a must but more conventional way of doing it). So we have&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//src/Worker/worker.ts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;workerFunction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//we perform every operation we want in this function right here&lt;/span&gt;
   &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onmessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;MessageEvent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

      &lt;span class="nf"&gt;postMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Message has been gotten!&lt;/span&gt;&lt;span class="dl"&gt;'&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="c1"&gt;//This stringifies the whole function&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;codeToString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;workerFunction&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;//This brings out the code in the bracket in string&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;mainCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;codeToString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;codeToString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;indexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;codeToString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LastIndexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;//convert the code into a raw data&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;blob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;mainCode&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/javascript&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="c1"&gt;//A url is made out of the blob object and we're good to go&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;worker_script&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="nf"&gt;createObjectURL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;worker_script&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is my React Component accessing the worker file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//src/App.tsx&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;worker_script&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Worker/worker&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;worker&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
     &lt;span class="nx"&gt;worker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;worker_script&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

   &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;postMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Beunos Dias!&lt;/span&gt;&lt;span class="dl"&gt;'&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Web&lt;/span&gt; &lt;span class="nx"&gt;Workers&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Because my useEffect doesn't have a dependency, the worker.postMessage function will be called once the page load and no more, until you refresh the page again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;once that is done, you can just run your code with a simple &lt;strong&gt;npm run dev&lt;/strong&gt; this will build your whole project and serve it on port &lt;strong&gt;5173&lt;/strong&gt;, yours might be a different port due to different configuration. In addtion, the build up process is lightning fast ⚡⚡, I recommend using VITE for your projects...&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Time Complexity of JavaScript Array Methods (Part One)</title>
      <dc:creator>Martins Olumide</dc:creator>
      <pubDate>Fri, 01 Sep 2023 07:36:08 +0000</pubDate>
      <link>https://dev.to/martinsolumide8/time-complexity-of-javascript-array-methods-part-one-210c</link>
      <guid>https://dev.to/martinsolumide8/time-complexity-of-javascript-array-methods-part-one-210c</guid>
      <description>&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt; array methods are simply function (also called method) that perform specific task and computations on the array it is called on. Majority of the time, they either return a new array, mutate an existing array, search an array, or return some truthy or falsely value based on a condition or statement. Knowing the time complexity of the array methods being used is not only eye-opening, it also allow enhance the performance of our programs and applications.&lt;/p&gt;

&lt;p&gt;So, lets dive in my JavaScript Geeks 😎👨🏽‍💻;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Array.pop()&lt;/strong&gt;:
This array method is the type that returns an item (generically called &lt;strong&gt;element&lt;/strong&gt;) from an array, &lt;strong&gt;pop()&lt;/strong&gt; removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. let's see an example.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-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;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Martins&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tobby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rielle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;//return 'Rielle' since it is the last element of the array&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;emptyNames&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;//returns undefined since there are no element in the array&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from the example above, think about the names in the array as &lt;strong&gt;people&lt;/strong&gt; on a &lt;strong&gt;queue&lt;/strong&gt;, since &lt;strong&gt;pop()&lt;/strong&gt; return the last element, the last &lt;strong&gt;person&lt;/strong&gt; on the queue will be removed and returned. And doing this simply have no effect on the rest of the &lt;strong&gt;people&lt;/strong&gt; since there is no need for reindexing of rest of the people in the queue. This implies that the time complexity to remove an &lt;strong&gt;element&lt;/strong&gt; in an array is &lt;strong&gt;O(1)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;2..&lt;strong&gt;Array.push()&lt;/strong&gt;:&lt;br&gt;
&lt;strong&gt;push()&lt;/strong&gt; is an array method that appends a new elements to the end of an array, and returns the new length of the array. let's proceed using our names array;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Martins&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tobby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;//This is our new array since 'Rielle' has been removed&lt;/span&gt;
&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Wick&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ['Dave', 'Martins', 'Tobby', 'Wick']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;push()&lt;/strong&gt; is performing the opposite operation of the &lt;strong&gt;pop()&lt;/strong&gt; method. &lt;strong&gt;pop()&lt;/strong&gt; removes, &lt;strong&gt;push()&lt;/strong&gt; adds. So, what do you think the Time complexity to add to people on the queue will be? my answer is &lt;strong&gt;O(1)&lt;/strong&gt;. How I got my answer?, well adding a new &lt;strong&gt;person&lt;/strong&gt; to that &lt;strong&gt;names&lt;/strong&gt; array doesn't require the change of the &lt;strong&gt;indexes&lt;/strong&gt; of the &lt;strong&gt;persons&lt;/strong&gt; in the array therefore, the only person changing index is the new &lt;strong&gt;person&lt;/strong&gt; being added.&lt;/p&gt;

&lt;p&gt;3..&lt;strong&gt;Array.Unshift()&lt;/strong&gt;:&lt;br&gt;
&lt;strong&gt;unshift()&lt;/strong&gt; is an array method that adds a new element to the start of an array i.e &lt;code&gt;array index 0&lt;/code&gt;, It is working in same way the &lt;strong&gt;array.push()&lt;/strong&gt; is but different postion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Martins&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tobby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wick&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unshift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Maroon&lt;/span&gt;&lt;span class="dl"&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ['Maroon', 'Dave', 'Martins', 'Tobby', 'Wick']&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the above example shows that &lt;strong&gt;Maroon&lt;/strong&gt; has taken the postion of index 0, which was the initial position of &lt;strong&gt;Dave&lt;/strong&gt;. This signifies that &lt;strong&gt;Dave's&lt;/strong&gt; index is now 1 and same is applicable to the rest of the elements in the &lt;strong&gt;array&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//initial indexing&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Martins&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tobby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wick&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;Dave&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="nx"&gt;Martins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="nx"&gt;Tobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="nx"&gt;Wick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;

&lt;span class="c1"&gt;//latest indexing since calling the unshift method&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Maroon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Martins&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tobby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wick&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;Maroon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="nx"&gt;Dave&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="nx"&gt;Martins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="nx"&gt;Tobby&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="nx"&gt;Wick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The time complexity for this operation is &lt;strong&gt;O(n)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;4..&lt;strong&gt;Array.shift()&lt;/strong&gt;:&lt;br&gt;
The &lt;strong&gt;shift()&lt;/strong&gt; method of Array instances removes the first element from an array and returns that removed element. This method changes the length of the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;names&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Maroon&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Martins&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tobby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wick&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// returns Maroon&lt;/span&gt;
&lt;span class="c1"&gt;//new array state&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Dave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Martins&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Tobby&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wick&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this also, reindexing would have to occur, consequently, the time complexity will be O(n) too.&lt;/p&gt;

&lt;p&gt;5..&lt;strong&gt;Array.forEach()&lt;/strong&gt;:&lt;br&gt;
The &lt;strong&gt;forEach()&lt;/strong&gt; method of Array instances executes a provided function once for each array element. It takes a callback function with a couple of parameters. Basically, it loops through each element in the &lt;strong&gt;array&lt;/strong&gt; and the time complexity for this operation is O(n) as the time taken will be proportional to the number of input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This is concludes the first part of the Time Complexity series, where we discuss thoroughly JavaScript methods and their time complexity. Stay tuned for the next parts I'll be uploading, have a nice day 🙂✌️&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>coding</category>
    </item>
    <item>
      <title>ALX Portfolio Project</title>
      <dc:creator>Martins Olumide</dc:creator>
      <pubDate>Sun, 16 Jul 2023 17:33:45 +0000</pubDate>
      <link>https://dev.to/martinsolumide8/alx-portfolio-project-38gd</link>
      <guid>https://dev.to/martinsolumide8/alx-portfolio-project-38gd</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3608abimsodn9jxf6hs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3608abimsodn9jxf6hs.jpg" alt=" " width="800" height="361"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;h2&gt;
  
  
  Title: Agrocademy - A Farmer, customer social forum
&lt;/h2&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Introduction&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Agricultural products are essential to not only the Farmers but to each and every one living in the world so far you eat, drink and make use of something Agro-based. In today's world where sole farmers aren't appreciated enough, an agro-based forum or social media can play a vital role in improving, motivating and inspiring more individual entrepreneurs to take on the farming business. I once had a relative who was a very successful sole farmer back in the 90s when the chance of making it as a sole commercial farming entrepreneur was very high. But since the emergence of large-scale commercial farming, the hope of such farmer succeeding is very slim, don't get me wrong, large-scale commercial farming has been a game changer and it is still very much needed but we seem to care less about small-scale commercial farmers.&lt;/p&gt;

&lt;p&gt;This blog post will delve into the inspiration behind the project, provide a summary of its anticipated accomplishments, and list the technical challenges encountered during the development process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inspiration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Farmers-Customer forum project was conceived out of an attempt to complete and create a useful application for my portfolio project, It will be easy to create just anyhow project to present and proceed to the 3months specialization but in the long run, I will be affected and my 9 months of assessment and test will probably be in vain. Furthermore, it is a portfolio project, not an ALX portfolio project alone, I knew creating a project I can show and talk about with people would be best. Additionally, It will be a crime if after the second sprint of the program I couldn't apply the knowledge and practical experience gained from the program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Agrocademy is aimed at providing a social media-like interface where farmers can upload images of farm products (any other images can be uploaded), create, delete, like, and comment, on a post, and also, users can have a global group(just a term I use for a chat interface with every authenticated user added). Users can also change profile images, follow a user and more. Future integrations and updates will improve the UX/UI, create a Direct message interface, and personalize feed post recommendations. The Project utilizes a 3-Tier Software Application architecture, with HTML, CSS, JavaScript and React-TypeScript for the UI/frontend, Node(Express TypeScript) for the backend and Sqlite3 (the next version will be migrated to MongoDB) for the database.&lt;/p&gt;

&lt;p&gt;Here are the steps I took in making progress in building the project.&lt;/p&gt;

&lt;p&gt;I. I first designed the database schema and write out the relationship between each table, row, and column. Sqlite3 was chosen because it is lightweight, and I can deploy it directly with the server.&lt;/p&gt;

&lt;p&gt;II. I started building my routes and middleware and some configurations. I have never used typescript on the backend, but I was taught to do hard things, so I used it and I'd say it was fun.&lt;/p&gt;

&lt;p&gt;III. Lastly, my client side. The front end was pretty easy and fast, maybe because it's my second year of building UIs LOL. I was faced with some challenges but I overcame.&lt;/p&gt;

&lt;p&gt;Here is the Diagram of my App architecture;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyf1ue1qo5v4i4vre0iqd.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyf1ue1qo5v4i4vre0iqd.jpg" alt=" " width="800" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical Challenges:&lt;/strong&gt;&lt;br&gt;
Time posed a significant technical challenge during development as I did the project all by myself which presented a lot of obstacles. The project was designed serve a lot of functionalities for the first version but time wasn't on our side, so I picked out the basic functionalities I want it to have. Also, the deployment is an ongoing challenge that I'm facing till now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Agrocademy is aimed at bringing together sole or individual commercial farmers for the common goal of encouraging, motivating, Inspiring and education each other. Also, it attract consumers to farm product which can be a great way to improve sales&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Profile&lt;/strong&gt;&lt;br&gt;
The project was developed by Martins Olumide, a software engineer and ALX Software Engineering student.&lt;/p&gt;

&lt;p&gt;Github: &lt;a href="https://github.com/Martins100-Tmd" rel="noopener noreferrer"&gt;https://github.com/Martins100-Tmd&lt;/a&gt;&lt;br&gt;
Landing Page: &lt;a href="https://agrocademy.netlify.app" rel="noopener noreferrer"&gt;https://agrocademy.netlify.app&lt;/a&gt;&lt;br&gt;
LinkedIn: &lt;a href="https://www.linkedin.com/martins100tmd" rel="noopener noreferrer"&gt;https://www.linkedin.com/martins100tmd&lt;/a&gt;&lt;/p&gt;

</description>
      <category>alx</category>
      <category>portfolioproject</category>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
