<?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: Rakshith holla</title>
    <description>The latest articles on DEV Community by Rakshith holla (@rakshithholla).</description>
    <link>https://dev.to/rakshithholla</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%2F496306%2F99f70166-9bd2-4ad0-938c-050dafa87624.jpeg</url>
      <title>DEV Community: Rakshith holla</title>
      <link>https://dev.to/rakshithholla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rakshithholla"/>
    <language>en</language>
    <item>
      <title>Negative Number to Positive Number without using abs() - asked in a interview</title>
      <dc:creator>Rakshith holla</dc:creator>
      <pubDate>Mon, 29 Mar 2021 04:22:26 +0000</pubDate>
      <link>https://dev.to/rakshithholla/negative-number-to-positive-number-without-using-abs-1fgi</link>
      <guid>https://dev.to/rakshithholla/negative-number-to-positive-number-without-using-abs-1fgi</guid>
      <description>&lt;p&gt;&lt;strong&gt;In&lt;/strong&gt; JavaScript, we have a method called absolute - &lt;code&gt;abs()&lt;/code&gt; to convert a &lt;em&gt;negative&lt;/em&gt; number into &lt;em&gt;positive&lt;/em&gt; number.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt; - &lt;code&gt;Math.abs(-7);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now&lt;/strong&gt;, we will see how we can perform the same operation without using the built-in absolute method,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const negativeToPositive = num =&amp;gt;{
  if(num &amp;lt; 0){
    return num * -1;
  }
  return num;
}

console.log(negativeToPositive(-8));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we have written a function which based on the input number given, converts the &lt;em&gt;negative&lt;/em&gt; number input to &lt;em&gt;positive&lt;/em&gt; and for &lt;em&gt;positive&lt;/em&gt; number input, it just returns the number.&lt;/p&gt;

&lt;p&gt;Hope this was helpful😊.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>programming</category>
    </item>
    <item>
      <title>Swapping two numbers using arithmetic operators </title>
      <dc:creator>Rakshith holla</dc:creator>
      <pubDate>Wed, 10 Feb 2021 03:49:51 +0000</pubDate>
      <link>https://dev.to/rakshithholla/swapping-two-numbers-using-arithmetic-operators-4a3j</link>
      <guid>https://dev.to/rakshithholla/swapping-two-numbers-using-arithmetic-operators-4a3j</guid>
      <description>&lt;p&gt;&lt;em&gt;We&lt;/em&gt; can perform swapping of two numbers without using temp variable and just by using arithmetic operators.&lt;/p&gt;

&lt;p&gt;Operators used are &lt;code&gt;+, -&lt;/code&gt; or &lt;code&gt;*, /&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, let us perform the swap using &lt;code&gt;+, -&lt;/code&gt; operators,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 5;
let b = 10;

//swap operations
a = a + b; //a = 15
b = a - b; //b = 5
a = a - b; //a = 10

//swap complete

console.log(a); //a is now 10
console.log(b); //b is now 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Now&lt;/strong&gt;, let us perform the swap using &lt;code&gt;*, /&lt;/code&gt; operators,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 7;
let b = 5;

//swap operations
a = a * b; //a = 35
b = a / b; //b = 7
a = a / b; //a = 5

//swap complete

console.log(a); //a is now 5
console.log(b); //b is now 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Hope this was helpful😊&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>operations</category>
      <category>programming</category>
      <category>javascript</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>JavaScript number sorting using default sort method</title>
      <dc:creator>Rakshith holla</dc:creator>
      <pubDate>Sun, 13 Dec 2020 03:37:53 +0000</pubDate>
      <link>https://dev.to/rakshithholla/javascript-number-sorting-using-default-sort-method-3joc</link>
      <guid>https://dev.to/rakshithholla/javascript-number-sorting-using-default-sort-method-3joc</guid>
      <description>&lt;p&gt;JavaScript has a default sort function which can be used to sort a list of values.&lt;/p&gt;

&lt;p&gt;usage -&amp;gt; &lt;code&gt;array_name.sort();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;However&lt;/strong&gt;, this sort method returns incorrectly for numbers, since this considers all values as string and sorts the list of numbers by comparing with the ASCII value of the individual values.&lt;/p&gt;

&lt;p&gt;This can be resolved by using comparison inside of the sort method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ascending order sorting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array_name.sort(function(a, b){
  return a - b;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;descending order or reverse sorting&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array_name.sort(function(a, b){
  return b - a;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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