<?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: Rajesh Ranjan</title>
    <description>The latest articles on DEV Community by Rajesh Ranjan (@rajesh6161).</description>
    <link>https://dev.to/rajesh6161</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%2F221392%2F5a3f0fd3-f0af-4823-a428-7b1eb31c4ccf.jpg</url>
      <title>DEV Community: Rajesh Ranjan</title>
      <link>https://dev.to/rajesh6161</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajesh6161"/>
    <language>en</language>
    <item>
      <title>Realtime Todo App Using React and Pocketbase</title>
      <dc:creator>Rajesh Ranjan</dc:creator>
      <pubDate>Sat, 08 Oct 2022 17:12:37 +0000</pubDate>
      <link>https://dev.to/rajesh6161/realtime-todo-app-using-react-and-pocketbase-3mf</link>
      <guid>https://dev.to/rajesh6161/realtime-todo-app-using-react-and-pocketbase-3mf</guid>
      <description>&lt;p&gt;I recently came across an outstanding Open Source backend project called PocketBase and its really amazing.&lt;br&gt;
Let's point out the good parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is written in Go, and everyone knows how _blazingly _ fast Go is.&lt;/li&gt;
&lt;li&gt;Open-source alternative to Firebase for smaller/hobby projects.&lt;/li&gt;
&lt;li&gt;Only one file to run, and can be used for &lt;strong&gt;RealtimeDB&lt;/strong&gt;, &lt;strong&gt;Authentication&lt;/strong&gt;(with different providers), &lt;strong&gt;File Storage&lt;/strong&gt;, &lt;strong&gt;RestAPI&lt;/strong&gt; and much more to come.&lt;/li&gt;
&lt;li&gt;Now the best part, it requires very very few lines to setup, and &lt;strong&gt;trust me its super easy to setup a realtime db really fast&lt;/strong&gt;, compared to Firebase which has a lot of boilerplate and setup at client side🤯.&lt;/li&gt;
&lt;li&gt;Local admin dashboard to take control of everything, can be self hosted easily, only one single file to run everything. Isn't this Amazing! 😲&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;br&gt;
Still under development so you might face some issues, but the development team is keen to resolve issues really fast.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;PocketBase Dashboard&lt;br&gt;
&lt;a href="https://media.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%2Fyceiwo2c3hvifx2fioq0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fyceiwo2c3hvifx2fioq0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can easily get the required code for your APIs here easily:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2Ffj3070w1e1bzj4u8yvs6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Ffj3070w1e1bzj4u8yvs6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You can setup your own rules for the access to APIs easily:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fvmcsz0o1ar1gn04akcyd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fvmcsz0o1ar1gn04akcyd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created this simple todo app using React+PocketBase, which supports creation and updation of todo in realtime.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fciwvrrcklgvthqo9vu2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fciwvrrcklgvthqo9vu2l.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download PocketBase from &lt;a href="https://pocketbase.io/docs/" rel="noopener noreferrer"&gt;&lt;/a&gt; according to your OS and run it using the command &lt;code&gt;pocketbase serve&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2F4fhmxrjihva3vss2uj47.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F4fhmxrjihva3vss2uj47.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open the Admin UI in browser and create a new collection named &lt;strong&gt;todoCollection&lt;/strong&gt; and add these fields to it and for now disable list action,create action and update action API rules to grant everyone access.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.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%2F8sf05skvdh0qjx879iwv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F8sf05skvdh0qjx879iwv.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That's it for the server side. Now coming to the client side:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new react-app with Tailwind if you want styling as mine else leave it and create a components folder with a file named TodoScreen.jsx.&lt;/li&gt;
&lt;li&gt;Install pocketbase js-SDK using &lt;code&gt;npm install pocketbase&lt;/code&gt; and import it in your file using: &lt;code&gt;import Pocketbase from 'pocketbase'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Pocketbase doc is itself sufficient and also the Admin Dashboard as I mentioned above where you can get the codes for your APIs to use.&lt;/li&gt;
&lt;li&gt;Just an important code that deals with the realtime in React:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// realtime
  useEffect(() =&amp;gt; {
    client.realtime.subscribe('todoCollection', function (e) {
      // console.log('realtime', e.record);
      let x = todos.filter((item) =&amp;gt; item.id !== e.record.id);
      setTodos([e.record, ...x]);
    });
    return () =&amp;gt; {
      client.realtime.unsubscribe(); // don't forget to unsubscribe
    };
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So what it does is, keep the looking for mutations in the collection as the client is subscribed to the collection. When some changes happens in the collection (create,update &amp;amp; delete) it gets fired and returns the new record.&lt;/p&gt;

&lt;p&gt;P.S (not going to write full code here because its easily understandable)&lt;/p&gt;

&lt;p&gt;Link to the full code: &lt;a href="https://github.com/rajesh6161/pocketbaseTodo" rel="noopener noreferrer"&gt;https://github.com/rajesh6161/pocketbaseTodo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks, and hoping this was of some help for devs looking out for Realtime DB with easy and fast setup.&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Google Sign in using Supabase, NextJS</title>
      <dc:creator>Rajesh Ranjan</dc:creator>
      <pubDate>Fri, 14 Jan 2022 15:36:00 +0000</pubDate>
      <link>https://dev.to/rajesh6161/google-sign-in-using-supabase-nextjs-46p3</link>
      <guid>https://dev.to/rajesh6161/google-sign-in-using-supabase-nextjs-46p3</guid>
      <description>&lt;p&gt;Supabase is really an awesome opensource 👌 alternative to Google's Firebase. Its really really simple to setup the database, authentication flow, uploading/downloading stuffs to/from the server. In this tutorial let's create a really simple authentication system that uses Google's oAuth to authenticate users and is **persistent **also incase you close the browser also.🤩&lt;/p&gt;

&lt;p&gt;For this tutorial we'll use NextJS for frontend (you can choose react/remix as you prefer), tailwind for little styling as it makes CSS styling superrrrr fast. &lt;a href="https://media.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%2F8rpmtk0gtbdtjaov7u0o.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F8rpmtk0gtbdtjaov7u0o.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Just a simple login page for demo:&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.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%2Fhz3w2hjpjg7nnjhe0fya.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fhz3w2hjpjg7nnjhe0fya.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Flvze8a1del1zh6vpw9xr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Flvze8a1del1zh6vpw9xr.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Setup your Google Cloud Project using the official tutorial from the Supabase team by going to this &lt;em&gt;&lt;a href="https://supabase.com/docs/guides/auth/auth-google" rel="noopener noreferrer"&gt;link&lt;/a&gt;:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Fork this &lt;em&gt;&lt;a href="https://github.com/rajesh6161/SupabaseOAuth" rel="noopener noreferrer"&gt;Repo&lt;/a&gt;&lt;/em&gt; and integrate in your own project easily plus you can easily customize it with no breaking changes.🤩&lt;/p&gt;

&lt;p&gt;Hope it helps you! ✌️ and if you have any issues please let me know in the comments.&lt;br&gt;
&lt;em&gt;&lt;a href="https://github.com/rajesh6161/SupabaseOAuth" rel="noopener noreferrer"&gt;https://github.com/rajesh6161/SupabaseOAuth&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>react</category>
    </item>
    <item>
      <title>Complete Missions and Get Certificate from Netlify *free</title>
      <dc:creator>Rajesh Ranjan</dc:creator>
      <pubDate>Sat, 08 Jan 2022 17:31:30 +0000</pubDate>
      <link>https://dev.to/rajesh6161/complete-missions-and-get-certificate-from-netlify-free-3f9k</link>
      <guid>https://dev.to/rajesh6161/complete-missions-and-get-certificate-from-netlify-free-3f9k</guid>
      <description>&lt;p&gt;I just got certificate from Jamstack Explorers from Netlify which consists of various tracks called missions which then consists of various crash courses on different topics like NuxtJS, NextJS, Strapi+Nuxt and many more. These all tutorials have code along exercises which is best and you will brush up your skills.&lt;br&gt;
Best for beginners with knowledge of Vue/React and web fundamentals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LEQJzgGe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytq2qat04lonrw991zwz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LEQJzgGe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ytq2qat04lonrw991zwz.jpg" alt="Image description" width="880" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lAre_0NJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bayj6sz13c2c3pveo9zq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lAre_0NJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bayj6sz13c2c3pveo9zq.jpg" alt="Image description" width="880" height="661"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check this out here --&amp;gt; &lt;a href="https://explorers.netlify.com/missions"&gt;https://explorers.netlify.com/missions&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>beginners</category>
      <category>nextjs</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Checkout my new Portfolio Page</title>
      <dc:creator>Rajesh Ranjan</dc:creator>
      <pubDate>Tue, 04 Jan 2022 19:15:09 +0000</pubDate>
      <link>https://dev.to/rajesh6161/checkout-my-new-portfolio-page-4a63</link>
      <guid>https://dev.to/rajesh6161/checkout-my-new-portfolio-page-4a63</guid>
      <description>&lt;p&gt;No doubt Next.js and Tailwind CSS are best combos out there so I also tried and made my own portfolio using these two awesome technologies and yeah the killer firebase alternative Supabase. Just wow🤩 I am really amazed by supabase's fast setup and easy to access dashboard that really helped me make this portfolio successful. &lt;br&gt;
I am sharing some screenshots and link to my portfolio please have a look and do let me know what else I can add to make it better.&lt;br&gt;
P.S. I am a fresher.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yP7BbOjh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/325d6mlo0dlsmj1xf8ev.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yP7BbOjh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/325d6mlo0dlsmj1xf8ev.jpg" alt="Image description" width="880" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jFQBBvaK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jtnnsmjw89fc0lgokbm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jFQBBvaK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jtnnsmjw89fc0lgokbm.jpg" alt="Image description" width="880" height="409"&gt;&lt;/a&gt;&lt;br&gt;
P.S. Project links will be added later 😊&lt;br&gt;
&lt;a href="https://rajeshranjan.live/"&gt;https://rajeshranjan.live/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Reverse Lists, Add them, Reverse the sum and return the sum as a List</title>
      <dc:creator>Rajesh Ranjan</dc:creator>
      <pubDate>Mon, 28 Jun 2021 10:39:46 +0000</pubDate>
      <link>https://dev.to/rajesh6161/reverse-lists-add-them-reverse-the-sum-and-return-the-sum-as-a-list-4f2o</link>
      <guid>https://dev.to/rajesh6161/reverse-lists-add-them-reverse-the-sum-and-return-the-sum-as-a-list-4f2o</guid>
      <description>&lt;p&gt;I came around this problem while solving questions on leetcode. This is a very good problem of linked lists. Basically the problem says: You are given two linked lists, you have to add those lists by reversing them and again reverse your addition output and return it as a linked list 🤔. I will not go solving this problem in context of time complexity but rather I will try to simplify it to the most basic level.&lt;br&gt;
I'm using Java to solve this problem. I will be solving it from the scratch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. First let's create a node for the linked list.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Node {
        int data;
        Node next;

        public Node(int data) {
            this.data = data;
            next = null;
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;2. Function to add Nodes to the linked list:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public Node head = null;
    public Node tail = null;

    public void addNode(int data) {
        Node newNode = new Node(data);
        if (head == null) {
            head = newNode;
            tail = newNode;
        } else {
            tail.next = newNode;
            tail = newNode;
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;3. Function to display nodes in the list.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public void display() throws IllegalStateException {
        Node current = head;
        if (head == null) {
            throw new IllegalStateException("Your List is empty");
        }
        while (current != null) {
            System.out.println(current.data);
            current = current.next;
        }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The top 3 blocks of codes were normal implementation of the linked list and displaying them using the display function.&lt;br&gt;
Now, the function to reverse the linked list:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;4. Reversing the linked list iteratively (you can do that recursively also)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public Node reverse(Node start) throws IllegalStateException {
        if (start == null) {
            throw new IllegalStateException("List is empty");
        }
        Node current = start;
        Node prev = null;

        while (current != null) {
            Node next = current.next;
            current.next = prev;
            prev = current;
            current = next;
        }
        return prev;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;5. The most important step is to add the values from the list to a StringBuilder and convert it to integer and return it. We'll use this value in the main function.
Workaround: To add the values easily that's why we are doing this extra step.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static int arr(Node start) throws IllegalStateException {
        Node current = start;
        if (start == null) {
            throw new IllegalStateException("Your List is empty");
        }

        StringBuilder sb = new StringBuilder();

        while (current != null) {
            sb.append(current.data);
            current = current.next;
        }
        String str = sb.toString();
        int x = Integer.parseInt(str);
        return x; // string converted to int
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;6. Finally the main method:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String[] args) {
        // creating two demo lists 
        AddTwoNumbers list1 = new AddTwoNumbers();
        list1.addNode(1);
        list1.addNode(1);
        list1.addNode(6);

        AddTwoNumbers list2 = new AddTwoNumbers();
        list2.addNode(1);
        list2.addNode(9);
        list2.addNode(2);

        // reversing the lists
        Node x1 = list1.reverse(list1.head);
        Node x2 = list2.reverse(list2.head);

        // getting the returned integer representation of the lists
        int y1 = arr(x1);
        int y2 = arr(x2);

        // adding both the values that's why we did the 5th step to simplify this summing process
        int sum = y1 + y2;

        // convert again to string builder so that we can reverse it easily
        StringBuilder str = new StringBuilder();
        StringBuilder output = str.append(sum).reverse();

        // create a new list that will be returned
        AddTwoNumbers finalList = new AddTwoNumbers();

        // pass the values to the list
        for (int i = 0; i &amp;lt; output.length(); i++) {
            int x =Integer.parseInt(String.valueOf(output.charAt(i)));
            finalList.addNode(x);
        }

        // and, finally display it
        finalList.display();

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

&lt;/div&gt;



&lt;p&gt;I know this solution went too long but this is a good workaround of solving this problem easily.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>linkedlists</category>
      <category>java</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>An Intro To JavaScript Array Methods</title>
      <dc:creator>Rajesh Ranjan</dc:creator>
      <pubDate>Mon, 11 May 2020 11:01:01 +0000</pubDate>
      <link>https://dev.to/rajesh6161/an-intro-to-javascript-array-methods-273o</link>
      <guid>https://dev.to/rajesh6161/an-intro-to-javascript-array-methods-273o</guid>
      <description>&lt;p&gt;Arrays are one of the most basic Data Structures in every programming language.&lt;br&gt;
Every programmer must know the very basic concepts of array and how to use them efficiently. As arrays are already built-in in every programming language they are usually very efficient and are good choice to store and retrieve data easily.&lt;br&gt;
Many programming languages provide built-in array methods to increase the efficiency of a programmer, JavaScript also provides as such built-in array methods which are very powerful.&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's look at some of the important array methods in JavaScript
&lt;/h1&gt;
&lt;h3&gt;
  
  
  1. Array.push()
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Use this method to add one element to the end of the array

  let fruitList = ['Mango', 'Apple', 'Orange', 'Banana']
  fruitList.push('Guava') 
  console.log(fruitList)
  Outputs: ["Mango", "Apple", "Orange", "Banana", "Guava"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  2. Array.pop()
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Removes only one element from the end of the array

  let fruitList = ['Mango', 'Apple', 'Orange', 'Banana', "Guava"]
  fruitList.pop() 
  console.log(fruitList)
  Outputs: ["Mango", "Apple", "Orange", "Banana"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  3. Array.concat()
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Merges two arrays and outputs a new array

  let odd_nums = [1, 3, 5, 7]
  let even_nums = [2, 4, 6, 8]
  const my_nums = odd_nums.concat(even_nums)
  console.log(my_nums)
  Outputs: [1, 3, 5, 7, 2, 4, 6, 8]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  4. Array.shift()
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Removes one element from beginning

  let fruitList = ['Mango', 'Apple', 'Orange', 'Banana']
  fruitList.shift()
  console.log(fruitList)
  Outputs: ["Apple", "Orange", "Banana"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  5. Array.join()
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Returns a string out of an array by combining all the elements inside it

  let fruitList = ['Mango', 'Apple', 'Orange', 'Banana']

  const str1 = fruitList.join('')
  const str2 = fruitList.join(' ')
  const str3 = fruitList.join(',')
  console.log(str1, str2, str3)

  Outputs: "MangoAppleOrangeBanana"
            "Mango Apple Orange Banana"
            "Mango,Apple,Orange,Banana"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  6. Array.splice()
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  //Returns a new array from an existing array by removing elements specified         
  by their index number

  let fruitList = ['Mango', 'Apple', 'Orange', 'Banana']

  //fruitList.splice(startAtIndex, numberOfElementsToRemove)

  const myFruits = fruitList.splice(0, 2)
  console.log(myFruits)

  Outputs: ["Mango", "Apple"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;But this method also alters the base array which means the elements are literally removed from the base array.&lt;br&gt;
If we do a console.log() from the base array we can see that:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  console.log(fruitList)
  Outputs: ["Orange", "Banana"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Here, we can see that "Mango" and "Apple" are removed from the base array too.&lt;br&gt;
Array.splice() method is really a good method to add and remove elements from the array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;To add elements in the array using .splice() use this syntax:&lt;/em&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   fruitList.splice(0, 2, "Papaya", "Strawberry", "Pears")
   console.log(fruitList)
   Outputs: ["Papaya", "Strawberry", "Pears", "Orange", "Banana"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;So, how does this works at all?&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;To remove elements from the Array:-&lt;/strong&gt; &lt;em&gt;Array.splice()&lt;/em&gt; takes two arguments &lt;strong&gt;first&lt;/strong&gt;&lt;br&gt;
index to start removing the element and &lt;strong&gt;second&lt;/strong&gt; the number of elements we want to remove. Here, we can see we have started from index 0 and removed 2 elements from the fruitList array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To add elements to the array:-&lt;/strong&gt; &lt;em&gt;Array.splice()&lt;/em&gt; takes three parameters &lt;strong&gt;first&lt;/strong&gt; and &lt;strong&gt;second&lt;/strong&gt; arguments are used to specify the elements to remove starting from some index and number of elements to remove following the starting index. And, the &lt;strong&gt;third&lt;/strong&gt; parameter is used to specify what elements to insert. We can use an array too as the third parameter.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   let fruitList = ['Mango', 'Apple', 'Orange', 'Banana']      
   const myFruits = ['Carrot', 'Guava', 'Peach']
   fruitList.splice(0, 2, ...myFruits) //ES6 spread operator
   console.log(fruitList)
   Outputs: ["Carrot", "Guava", "Peach", "Orange", "Banana"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Here, we can clearly see that the first two fruits are removed from the fruitList array and myFruits have in added at that place.&lt;br&gt;
So, you will definitely say that what if I don't want to remove any fruits but I want to add my fruits to that fruitList also.&lt;br&gt;
So, to do that simply make the &lt;strong&gt;second&lt;/strong&gt; parameter 0, as we don't want any fruits to remove from the fruitList array.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let fruitList = ['Mango', 'Apple', 'Orange', 'Banana']      &lt;br&gt;
 const myFruits = ['Carrot', 'Guava', 'Peach']&lt;br&gt;
 fruitList.splice(0, 0, ...myFruits) //ES6 spread operator&lt;br&gt;
 console.log(fruitList)&lt;br&gt;
 Outputs:["Carrot", "Guava", "Peach", "Mango", "Apple", "Orange", "Banana"]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Iterator Functions
&lt;/h2&gt;

&lt;p&gt;These functions apply a function to each element of an array. And returns a value, a set of values, or a new array after applying the function to each element of an array.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Array.every()
&lt;/h3&gt;

&lt;p&gt;This method applies a function to each element of the array and checks whether each element of the array satisfies the criteria of the defined function and returns a boolean value &lt;em&gt;true&lt;/em&gt; or &lt;em&gt;false&lt;/em&gt; based on the function definition.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let nums = [2, 4, 6, 8]
  const isEven = nums.every((el) =&amp;gt; {
  if (el % 2 == 0) return true
  else return false
  })
  console.log(isEven) //returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's alter the nums array :-&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let nums = [2, 4, 6, 8, 5]
  const isEven = nums.every((el) =&amp;gt; {
  if (el % 2 == 0) return true
  else return false
  })
  console.log(isEven) //will now return false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Because in the first case all the numbers inside the nums array are even and all the numbers satisfy the function definition that each number must be divisible by 2. But, in second case we added an odd number which doesn't satisfy the function definition and return false.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Array.some()
&lt;/h3&gt;

&lt;p&gt;This method is just opposite of above &lt;em&gt;Array.every()&lt;/em&gt;. In this method if any one  the element in the array satisfies the function definition then it returns a boolean value based on that criteria.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let nums = [2, 4, 6, 8, 5]
  const isOdd = nums.some((el) =&amp;gt; {
  if (el % 2 != 0) return true
  else return false
  })
  console.log(isOdd) //returns true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As we can see the result is true which means there is at least one number in the array which is not DIVISIBLE by 2 and which means it is an odd number.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Array.map()
&lt;/h3&gt;

&lt;p&gt;This method returns a brand new array out of the base array by applying the function to each element of the base array.&lt;br&gt;
Let's see an example:-&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let fruitList = ['Mango', 'Apple', 'Guava', 'Papaya'];
  let eat = fruitList.map(fruit =&amp;gt; {
     return `I want to eat ${fruit}`;
  })
  console.log(eat)

  Outputs: ["I want to eat Mango", "I want to eat Apple", 
           "I want to eat Guava", "I want to eat Papaya"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Let's see one more example:-&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let nums = [2,4,6,8,10];&lt;br&gt;
let squaredNums = nums.map(num =&amp;gt; {&lt;br&gt;
           return Math.pow(num, 2);&lt;br&gt;
})&lt;br&gt;
console.log(squaredNums);&lt;br&gt;
Outputs: [4, 16, 36, 64, 100]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Array.filter()
&lt;/h3&gt;

&lt;p&gt;This method is some what similar to Array.every() but instead of returning a boolean value it returns a brand new array on the basis of the function definition. &lt;em&gt;As the name suggests it filters out the elements from the array if the conditions are satisfied.&lt;/em&gt;&lt;br&gt;
Let's see an example that filters out even numbers from the array:-&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   let nums = [2,3,7,8,10,5]
   let filteredNums = nums.filter(num =&amp;gt; {
      return num % 2 == 0;
   })
   console.log(filteredNums)
   Outputs: [2, 8, 10]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Let's see one more example to filter out numbers from the array which are greater than 15:-&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;let nums = [21,32,7,8,12,52,6]&lt;br&gt;
   let filteredNums = nums.filter(num =&amp;gt; {&lt;br&gt;
       return num&amp;gt;15;&lt;br&gt;
   })&lt;br&gt;
   console.log(filteredNums)&lt;br&gt;
   Outputs: [21, 32, 52]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  11. Array.reduce()
&lt;/h3&gt;

&lt;p&gt;This method doesn't return a brand new array instead it returns a single value by applying the function to an accumulator and the successive elements of an array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let's take an array of numbers and we want to add all the numbers inside the array to get a total value. To achieve this we will use &lt;strong&gt;for&lt;/strong&gt; loop&lt;/em&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   let myNums = [1,2,3,4,5];
   let total = 0;
   for(let i=0;i&amp;lt;myNums.length;i++)
       total += myNums[i];
   console.log(total) //15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;But we can achieve the same result using the &lt;em&gt;Array.reduce()&lt;/em&gt; method easily.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let myNums = [1,2,3,4,5]
  const sum = myNums.reduce((a,num) =&amp;gt; {
       return a+num;
  },0)
  console.log(sum) //outputs: 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;em&gt;.reduce()&lt;/em&gt; method takes in three parameters, which are a (accumulator), num, and initial value, &lt;em&gt;viz.&lt;/em&gt; 0 here.&lt;br&gt;
What &lt;strong&gt;a&lt;/strong&gt; does is that it takes in the initial value &lt;em&gt;viz.&lt;/em&gt; 0 for now and keeps on adding the &lt;em&gt;num&lt;/em&gt; from the array to the &lt;strong&gt;a&lt;/strong&gt;ccumulator until the last index is reached in the array.&lt;/p&gt;

&lt;p&gt;Let's see one more example:-&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let myNums = [1,2,3,4,5]
  const sum = myNums.reduce((a,num) =&amp;gt; {
       return a+num;
  },10)
  console.log(sum) //now outputs 25
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Because we have assigned initial value to our accumulator as 10, so it starts adding the numbers to 10 and so on until the last index of array is reached.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  12. Array.sort()
&lt;/h3&gt;

&lt;p&gt;This method is really a simple method to sort the elements inside the array which are composed of alphabets. This method sorts the elements in a &lt;strong&gt;lexical order&lt;/strong&gt; which is similar to the way in which we search a word in a dictionary. &lt;strong&gt;But, this method doesn't works with numbers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's take an example to see how this method works:-&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let fruitList = ['Mango', 'Apple', 'Orange', 'Banana', "Guava"]
  let sortedFruits = fruitList.sort()
  console.log(sortedFruits)

  Outputs: ["Apple", "Banana", "Guava", "Mango", "Orange"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;As we can clearly see the &lt;strong&gt;.sort()&lt;/strong&gt; method has sorted our &lt;em&gt;fruitList&lt;/em&gt; array&lt;br&gt;
in alphabetical order.&lt;br&gt;
But we can also use &lt;em&gt;Array.sort()&lt;/em&gt; to sort our nums array too by passing a function to the &lt;em&gt;Array.sort()&lt;/em&gt; method. And, what this function will do is that it will simply compare the nums in the array and sort them by following a simple rule &lt;em&gt;viz.&lt;/em&gt;&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;If the number returned is negative, the left operand is less than the right operand, if the number returned is zero, the left operand is equal to the right operand and if the number returned is positive, the left operand is greater than the right operand.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Let's see the example:-&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   let compareNums =(num1, num2)=&amp;gt; {
       return num1-num2;
   }
   let myNums = [5,27,85,4,78,32];
   const sortedNums = myNums.sort(compareNums)
   console.log(sortedNums)

   Outputs: [4, 5, 27, 32, 78, 85]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So, we have seen some of the JavaScript array methods, there are many more such methods but these are some of the methods that are used regularly.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
