<?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: Sudharsanan S R</title>
    <description>The latest articles on DEV Community by Sudharsanan S R (@sudharsanansr).</description>
    <link>https://dev.to/sudharsanansr</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%2F248085%2F5764602f-0fef-4f90-8341-bf4fdeb16e4c.png</url>
      <title>DEV Community: Sudharsanan S R</title>
      <link>https://dev.to/sudharsanansr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sudharsanansr"/>
    <language>en</language>
    <item>
      <title>QuickSort</title>
      <dc:creator>Sudharsanan S R</dc:creator>
      <pubDate>Sun, 27 Sep 2020 13:08:01 +0000</pubDate>
      <link>https://dev.to/sudharsanansr/quicksort-37ac</link>
      <guid>https://dev.to/sudharsanansr/quicksort-37ac</guid>
      <description>&lt;p&gt;It's been a while since I posted, today we will discuss QuickSort.&lt;/p&gt;

&lt;p&gt;Before that, if you haven't seen my last post. Click on the below link.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/sudharsanansr" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F248085%2F5764602f-0fef-4f90-8341-bf4fdeb16e4c.png" alt="sudharsanansr"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/sudharsanansr/merge-sort-4dj1" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Merge Sort&lt;/h2&gt;
      &lt;h3&gt;Sudharsanan S R ・ Aug 31 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#algorithms&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#sorting&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#arrays&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;The topic for today is QuickSort!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quicksort is a divide &amp;amp; conquer algorithm.&lt;/li&gt;
&lt;li&gt;It uses recursion to sort the elements.&lt;/li&gt;
&lt;li&gt;It considers pivot element as a base value and sorts rest of the elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Pseudocode
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;Base condition:&lt;/em&gt; Return the array as it is if the array length is equal to 1.&lt;/li&gt;
&lt;li&gt;Identify the pivot value&lt;/li&gt;
&lt;li&gt;Get all the elements less than the pivot value on one side.&lt;/li&gt;
&lt;li&gt;Get all the elements greater than the pivot value on another side.&lt;/li&gt;
&lt;li&gt;Repeat steps 2,3 &amp;amp; 4&lt;/li&gt;
&lt;li&gt;Return final sorted array&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Click below link to view the pictorial representation of how the algorithm works&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%2Fi%2F7y644x649ajo38xcdw78.png" 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%2Fi%2F7y644x649ajo38xcdw78.png" alt="Geeks For Geeks reference" width="703" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://www.geeksforgeeks.org/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Implementation in JavaScript
&lt;/h1&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%2Fi%2Fkmbttwj1ys46hggutmgg.png" 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%2Fi%2Fkmbttwj1ys46hggutmgg.png" alt="QuickSort implementation in JS" width="800" height="522"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;below is the result&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%2Fi%2Fvtqz76fctvquiu9dwlz7.png" 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%2Fi%2Fvtqz76fctvquiu9dwlz7.png" alt="Result" width="800" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this is useful, will catch you soon on my next post!&lt;/p&gt;

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

&lt;p&gt;Thanks,&lt;br&gt;
Sudharsanan Ravichandran&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>sorting</category>
      <category>arrays</category>
    </item>
    <item>
      <title>Merge Sort</title>
      <dc:creator>Sudharsanan S R</dc:creator>
      <pubDate>Mon, 31 Aug 2020 13:13:14 +0000</pubDate>
      <link>https://dev.to/sudharsanansr/merge-sort-4dj1</link>
      <guid>https://dev.to/sudharsanansr/merge-sort-4dj1</guid>
      <description>&lt;p&gt;Hope you read my previous article on the selection sort, and how it is similar to Insertion sort.&lt;/p&gt;

&lt;p&gt;If not, check out this article below.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/sudharsanansr" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F248085%2F5764602f-0fef-4f90-8341-bf4fdeb16e4c.png" alt="sudharsanansr"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/sudharsanansr/selection-sort-43n" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Selection Sort&lt;/h2&gt;
      &lt;h3&gt;Sudharsanan S R ・ Aug 24 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#algorithms&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#sorting&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;We will see the Merge Sort today.&lt;/p&gt;

&lt;p&gt;Merge Sort is a divide and conquer sorting algorithms, which uses recursion to sort.&lt;/p&gt;

&lt;p&gt;Here is a pictorial representation of how it works.&lt;/p&gt;

&lt;p&gt;(Top -&amp;gt; Bottom)&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%2Fi%2Fsmjnqbttfxwi0ncb8s5b.png" 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%2Fi%2Fsmjnqbttfxwi0ncb8s5b.png" alt="marge-sort-flow-diagram" width="800" height="687"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above diagram, we are dissecting the elements of array based on a pivot value (depending on the length of the array).&lt;/p&gt;

&lt;p&gt;Since the dissection happens back to back due to recursion, we would need a base condition. Here our base condition is to return the input if the "input.length" is less than or equal to 1.&lt;/p&gt;

&lt;p&gt;Once the elements are dissected, the sorting happens.&lt;/p&gt;

&lt;p&gt;Here we compare the values of 2 arrays dissected starting from the index "0". If the value on the left found to be smaller, we will push that element to the result array and increment the counter on the left array (only), same goes to the array on right. &lt;/p&gt;

&lt;p&gt;We do it repeatedly until the counter value reaches the array length.&lt;/p&gt;

&lt;p&gt;In the end, there will be one element either in right or the left array which needs to be pushed to the result (the largest element), so we concatenate that value while returning the result.&lt;/p&gt;

&lt;p&gt;Video reference (Start from 3:08) &lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/kgBjXUE_Nwc"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Below is the implementation in JavaScript for the Merge Sort algorithm&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%2Fi%2Fg76a2deic0tayny73jxe.png" 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%2Fi%2Fg76a2deic0tayny73jxe.png" alt="merge-sort-js-implementation" width="800" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the result.&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%2Fi%2F4bt7ouswlv9t3sgpygxu.png" 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%2Fi%2F4bt7ouswlv9t3sgpygxu.png" alt="merge-sort-js-implementation-result" width="800" height="218"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you find this helpful.&lt;/p&gt;

&lt;p&gt;Please share your feedback, will see you again.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br&gt;
Sudharsanan Ravichandran&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>sorting</category>
      <category>arrays</category>
    </item>
    <item>
      <title>Selection Sort</title>
      <dc:creator>Sudharsanan S R</dc:creator>
      <pubDate>Mon, 24 Aug 2020 13:51:58 +0000</pubDate>
      <link>https://dev.to/sudharsanansr/selection-sort-43n</link>
      <guid>https://dev.to/sudharsanansr/selection-sort-43n</guid>
      <description>&lt;p&gt;As we continue to look into sorting algorithms we will learn what's &lt;strong&gt;Selection Sort&lt;/strong&gt; today.&lt;/p&gt;

&lt;p&gt;Selection Sort is another naive sorting approach, can be used for sorting smaller data sets.&lt;/p&gt;

&lt;p&gt;First, let's look at the &lt;em&gt;Pseudo code&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For this example, let's imagine we are looking at an unsorted set of cards&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the smallest card and swap it with the first element of the array.&lt;/li&gt;
&lt;li&gt;Find the second smallest card and swap it with the second element of the array.&lt;/li&gt;
&lt;li&gt;Repeat finding the next-smallest card, and swapping it into the correct position until the array is sorted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Simple! isn't it?!&lt;/p&gt;

&lt;p&gt;Below is the implementation of Selection Sort in JS&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%2Fi%2Fnyqabnd6jmm8zpzd8tf5.png" 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%2Fi%2Fnyqabnd6jmm8zpzd8tf5.png" alt="implementation" width="800" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once after you execute the function below is the response&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%2Fi%2Fgij8h2oadyt7gvd0ffm1.png" 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%2Fi%2Fgij8h2oadyt7gvd0ffm1.png" alt="result" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I mentioned earlier on the below article.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/sudharsanansr" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&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%2Fuser%2Fprofile_image%2F248085%2F5764602f-0fef-4f90-8341-bf4fdeb16e4c.png" alt="sudharsanansr"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/sudharsanansr/insertion-sort-27p" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Insertion Sort&lt;/h2&gt;
      &lt;h3&gt;Sudharsanan S R ・ Aug 21 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#sorting&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#algorithms&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;this video reference was really good to understand how similar Insertion Sort &amp;amp; Selection Sort are.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/pcJHkWwjNl4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Hope you like this article, please feel free to share your comments.&lt;/p&gt;

&lt;p&gt;Thanks again for stopping by 😊&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>sorting</category>
    </item>
    <item>
      <title>Insertion Sort</title>
      <dc:creator>Sudharsanan S R</dc:creator>
      <pubDate>Fri, 21 Aug 2020 17:59:00 +0000</pubDate>
      <link>https://dev.to/sudharsanansr/insertion-sort-27p</link>
      <guid>https://dev.to/sudharsanansr/insertion-sort-27p</guid>
      <description>&lt;p&gt;This is my second post on Sorting algorithms.&lt;/p&gt;

&lt;p&gt;We will see how &lt;em&gt;Insertion Sort&lt;/em&gt; works&lt;/p&gt;

&lt;p&gt;Insertion sort is another naive sorting approach which can't be used for large data sets. But, if you understand the crux of how it works under the hood. It's easy to implement.&lt;/p&gt;

&lt;p&gt;Below is the Pseudocode for the sorting algorithm&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pseudocode&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Element at the very first index is assumed sorted&lt;/li&gt;
&lt;li&gt;You pick the element at the second index&lt;/li&gt;
&lt;li&gt;Compare the element with the sorted subarray list (one element at a time)&lt;/li&gt;
&lt;li&gt;If element compared within the sorted subarray list is bigger than the current you will shift them one place to the right.&lt;/li&gt;
&lt;li&gt;You will repeat the above process until either you reach the left end of the array or if the element compared with is less than the current element.&lt;/li&gt;
&lt;li&gt;Repeat the process until all elements are sorted.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I got this beautiful visual representation of how it works in a nutshell. &lt;/p&gt;

&lt;p&gt;Please click on the below reference link to check it out.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tutorialsbookmarks.com/wp-content/uploads/2019/08/Insertion-sort-example.gif" rel="noopener noreferrer"&gt;https://tutorialsbookmarks.com/wp-content/uploads/2019/08/Insertion-sort-example.gif&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Below is the source code implemented in JavaScript.&lt;/p&gt;

&lt;p&gt;This is not a pure function-based implementation!&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%2Fi%2Fjieyzle3roi3h6enh4pp.png" 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%2Fi%2Fjieyzle3roi3h6enh4pp.png" alt="Insertion Sort JS" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope you like this, please share your comments and I am looking forward to any optimizations that can be done here.&lt;/p&gt;

&lt;p&gt;On my next post, we will see the Selection Sort and also understand how it's similar to the Insertion sort we saw above.&lt;/p&gt;

&lt;p&gt;For this content, I got an awesome video reference that I can't wait to share.&lt;/p&gt;

&lt;p&gt;See you in the next post!&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br&gt;
Sudharsanan Ravichandran&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>sorting</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Bubble Sort</title>
      <dc:creator>Sudharsanan S R</dc:creator>
      <pubDate>Thu, 20 Aug 2020 14:50:39 +0000</pubDate>
      <link>https://dev.to/sudharsanansr/bubble-sort-497c</link>
      <guid>https://dev.to/sudharsanansr/bubble-sort-497c</guid>
      <description>&lt;p&gt;Hello Dev Community,&lt;/p&gt;

&lt;p&gt;Happy to share my very first article. I recently started with #100DaysOfCode on Twitter. I got to meet awesome developers who were very good &amp;amp; unique.&lt;/p&gt;

&lt;p&gt;Often saw many people sharing useful information for free to help fellow newbies &amp;amp; developers. This got me thinking, I haven't done much for the dev community and this article is just a brainchild.&lt;/p&gt;

&lt;p&gt;I will try to go through one of the sorting algorithms (easiest to catch) that I learnt so far in the past few days.&lt;/p&gt;

&lt;p&gt;Before we move on any further, I just want to say, it's easy!&lt;/p&gt;

&lt;p&gt;We will start with the classic &lt;strong&gt;Bubble Sort&lt;/strong&gt; algorithm&lt;/p&gt;

&lt;p&gt;You can go through this video from HackerRank to get a hint on how it works?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=6Gv8vg0kcHc" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=6Gv8vg0kcHc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Bubble Sort, we compare two of the adjacent element and swap their places. Upon one successful iteration over the elements, you will get the largest of the number on the right-hand side of the array. We will not touch the sorted element (right-hand side) on the successive iteration.&lt;br&gt;
You have to repeat the same until your array is sorted.&lt;/p&gt;

&lt;p&gt;Below is a pure function based implementation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bubbleSort(iterarr){

    if(!Array.isArray(iterarr)){ // Checking given input is a valid array
        console.error('Not an array!');
        return;
    }

    let arr = [...iterarr]; // Copied the array elements using spread operator

    if(arr.length == 1){
        return arr; //If array has only one element it's already sorted
    }

    let isSorted = false; //Assuming the array is not sorted

    while(!isSorted){ //Loop breaks if the array is sorted
        isSorted = true; //Assuming the array is sorted
        for(let i = 0; i &amp;lt; arr.length - 1; i++){ //Loop for iterating through elements
            if(arr[i] &amp;gt; arr[i+1]){ //Trying to check which of the element is bigger current(i) or the next element(i+1)
                let temp = arr[i];
                arr[i] = arr[i+1];
                arr[i+1] = temp; //Above 3 lines does the swapping using the temp variable
                isSorted = false; //If swap happens that means array is not sorted yet
            }
        }
    }
    return arr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Though this is not an optimal sorting method, it's one of the easiest.&lt;/p&gt;

&lt;p&gt;I hope you like this article. Please share any comments if you have, I will try to address them one step at a time.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br&gt;
Sudharsanan Ravichandran&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
  </channel>
</rss>
