<?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: Patkul Shah</title>
    <description>The latest articles on DEV Community by Patkul Shah (@tapesh123).</description>
    <link>https://dev.to/tapesh123</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%2F213988%2F2b469f07-6a6e-4b46-8e23-29532ad19c6c.jpeg</url>
      <title>DEV Community: Patkul Shah</title>
      <link>https://dev.to/tapesh123</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tapesh123"/>
    <language>en</language>
    <item>
      <title>Integer Reversal - Common Interview Problem</title>
      <dc:creator>Patkul Shah</dc:creator>
      <pubDate>Wed, 16 Oct 2019 13:37:35 +0000</pubDate>
      <link>https://dev.to/tapesh123/integer-reversal-common-interview-problem-1ela</link>
      <guid>https://dev.to/tapesh123/integer-reversal-common-interview-problem-1ela</guid>
      <description>&lt;p&gt;Hi all, I'll make this quick and go straight to the meat and paneer :) of things. &lt;/p&gt;

&lt;p&gt;Reversing a string or reversing a number is one of the common questions asked at programming interviews. Let’s take a look at how this is done.&lt;/p&gt;

&lt;p&gt;Limitations/Rules: &lt;br&gt;
negative numbers should remain negative &lt;br&gt;
any leading zeroes must be removed&lt;br&gt;
function that can accept floats or integers&lt;br&gt;
the function will return integers a integers&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//enclose your code in parsefloat first&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reversedNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&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="nx"&gt;reverse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;//make sure you multiply by this to correct the negative sign &lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;reverseNum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 4321&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ok, so now we have mentioned the limitations, let's break down the following arrow function solution into step.Arrow functions have an implicit return value — if they can be written in one line, without the need for the{} braces.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Notice, first we must convert the number into a string in order to use the split array method. num.toString() converts the given number into a String so we can use the split function on it next. &lt;/li&gt;
&lt;li&gt;the split function - takes a a string and turns it into a array of characters, we need to do this in order to use the next array reverse function. &lt;/li&gt;
&lt;li&gt;Reverse the array - num.reverse() reverses the order of the items in the array &lt;/li&gt;
&lt;li&gt;join() function - num.join() function - combines the reversed characters into a string.&lt;/li&gt;
&lt;li&gt;Parse the input value into a floating point number. parseFloat(num) converts num into a float from a String. Notice the example below, it removes the 0s and the - and gives you only the float point numbers.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0012345-&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nb"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;//num - 12345 &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Multiply it by the sign of the original number in order to maintain the negative value. num* Math.sign(num)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;original&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5432100&lt;/span&gt;
&lt;span class="c1"&gt;//num = 12345&lt;/span&gt;

&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5432100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;//num = -12345&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and there  you have it! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>interview</category>
      <category>frontend</category>
      <category>react</category>
    </item>
    <item>
      <title>ES6 Block Scope is The New IIFE</title>
      <dc:creator>Patkul Shah</dc:creator>
      <pubDate>Mon, 07 Oct 2019 14:49:54 +0000</pubDate>
      <link>https://dev.to/tapesh123/es6-block-scope-is-the-new-iife-2lg2</link>
      <guid>https://dev.to/tapesh123/es6-block-scope-is-the-new-iife-2lg2</guid>
      <description>&lt;p&gt;I will be summarizing how we don't really need IIFE anymore when using ES6 Block Scope. Specifically, we will learn how let and const are going to be super useful! Basically, let and const is beneficial if you need to scope something to a block, or if you want to make a variable that cannot be changed by accident or on purpose. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background on IIFE (skip if you already know):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An IIFE function runs itself immediately, and it creates a scope where nothing is going to leak into the parent scope. In our case, nothing is going to leak into the global scope of the window.&lt;/p&gt;

&lt;p&gt;Creating a named function pollutes the global name space. It also means the named function is hanging around. With the function hanging out, oh-so readily available, it could accidentally be invoked again. IIFE isn’t named and therefore can’t accidentally be called later — avoiding any potential security implications.&lt;br&gt;
&lt;iframe src="https://jsfiddle.net/Tapesh/6sxezwv5/20//embedded/js,result//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you try to call name in the console now, it’s not undefined, it’s blank because, like I mentioned, it’s just blank because that is a property that lives on the window in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HERE COMES LET AND CONST TO THE RESCUE!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With let and const variables, we don’t need a function for our variables to be scoped to that.&lt;/p&gt;

&lt;p&gt;Why? Because let and const use block scope.&lt;/p&gt;

&lt;p&gt;Let’s start over with a const instead of a var&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/Tapesh/6sxezwv5/25//embedded/js,result//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If we call this in the console, we’ll see 'Awesomeness', but if we wrap it in curly brackets ( see first lines of code below )&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/Tapesh/6sxezwv5/28//embedded/js,result//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Our const is going to be scoped to that block. If you try to call name in the console, we’ll get the window’s name equal to "result", whatever that means(you can explain it in the discussion section!). But if we add a console.log to our block ( see last lines of code above )&lt;/p&gt;

&lt;p&gt;You don’t the IIFE stuff anymore. You’re using let and const because they are going to be scoped to that block. Let me know what other examples you guys can think of in the discussion section below! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Spread Syntax (ES6) (Must know for React)</title>
      <dc:creator>Patkul Shah</dc:creator>
      <pubDate>Sun, 06 Oct 2019 16:27:36 +0000</pubDate>
      <link>https://dev.to/tapesh123/spread-syntax-es6-must-know-for-react-nh1</link>
      <guid>https://dev.to/tapesh123/spread-syntax-es6-must-know-for-react-nh1</guid>
      <description>&lt;p&gt;JavaScript is becoming more powerful every day (thanks to ES6 and Babel), new syntax and tools allow us to write concise code and the less code we have to write the less errors. This is for my skill reinforcement purpose but you if can learn valuable knowledge from this then be the force with you! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's start from examples:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: Combining/Intersecting two arrays &lt;/p&gt;

&lt;p&gt;In this code, we will use the old way of combining two arrays using concat then the second way is using the spread syntax. &lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/Tapesh/tbqj921g/5//embedded/js,result//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;There is not much of a difference here as we are just putting two arrays together but where things get interesting is when we want to insert an array in the middle of another array.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/Tapesh/tbqj921g/23//embedded/js,result//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt; — You can also use the spread operator on objects, this makes it very easy to make a copy of an object and not worry about object references and mutability which can lead to unexpected behavior.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/Tapesh/tbqj921g/51//embedded/js,result//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3&lt;/strong&gt; — Combining two objects - Notice the spread syntax which is separated by a comma in order to combine!&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/Tapesh/tbqj921g/56///embedded/js,result//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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