<?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: Himanshu Joshi</title>
    <description>The latest articles on DEV Community by Himanshu Joshi (@himanshu_joshi_d4c8a0fad3).</description>
    <link>https://dev.to/himanshu_joshi_d4c8a0fad3</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%2F2817924%2F11f15143-698d-4560-a134-2ec895689e67.png</url>
      <title>DEV Community: Himanshu Joshi</title>
      <link>https://dev.to/himanshu_joshi_d4c8a0fad3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/himanshu_joshi_d4c8a0fad3"/>
    <language>en</language>
    <item>
      <title>How Much is True?</title>
      <dc:creator>Himanshu Joshi</dc:creator>
      <pubDate>Fri, 07 Feb 2025 07:44:34 +0000</pubDate>
      <link>https://dev.to/himanshu_joshi_d4c8a0fad3/how-much-is-true-441i</link>
      <guid>https://dev.to/himanshu_joshi_d4c8a0fad3/how-much-is-true-441i</guid>
      <description>&lt;p&gt;Create a function which returns the number of *&lt;em&gt;true *&lt;/em&gt; values there are in an array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Examples&lt;/strong&gt;&lt;br&gt;
countTrue([true, false, false, true, false]) ➞ 2&lt;/p&gt;

&lt;p&gt;countTrue([false, false, false, false]) ➞ 0&lt;/p&gt;

&lt;p&gt;countTrue([]) ➞ 0&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Notes&lt;/strong&gt;&lt;br&gt;
Return 0 if given an empty array.&lt;br&gt;
All array items are of the type bool (true or false).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function countTrue(array){
   if(array.length==0){
       return 0;
   }
 return array.filter((val)=&amp;gt;(val==true)).length;
}
console.log(countTrue([true, false, false, true, false]));
console.log(countTrue([false, false, false, false]));
console.log(countTrue([]));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Tile Teamwork Tactics</title>
      <dc:creator>Himanshu Joshi</dc:creator>
      <pubDate>Fri, 07 Feb 2025 07:10:06 +0000</pubDate>
      <link>https://dev.to/himanshu_joshi_d4c8a0fad3/tile-teamwork-tactics-38i3</link>
      <guid>https://dev.to/himanshu_joshi_d4c8a0fad3/tile-teamwork-tactics-38i3</guid>
      <description>&lt;p&gt;In a board game, a piece may advance 1-6 tiles forward depending on the number rolled on a six-sided die. If you advance your piece onto the same tile as another player's piece, both of you earn a bonus.&lt;/p&gt;

&lt;p&gt;Can you reach your friend's tile number in the next roll? Create a function that takes your position a and your friend's position b and returns a boolean representation of whether it's possible to earn a bonus on any die roll.&lt;/p&gt;

&lt;p&gt;Examples&lt;/p&gt;

&lt;p&gt;possibleBonus(3, 7) ➞ true&lt;/p&gt;

&lt;p&gt;possibleBonus(1, 9) ➞ false&lt;/p&gt;

&lt;p&gt;possibleBonus(5, 3) ➞ false&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function possibleBonus(a, b) {
    if (a &amp;gt;= b) {
        return false;
    }
    let result = b - a;
    return result &amp;lt;= 6;
}
console.log(possibleBonus(3, 6)); // true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>challenge</category>
    </item>
    <item>
      <title>DSA Problem #1 Determine If Two Numbers Add up to a Target Value (PHP)</title>
      <dc:creator>Himanshu Joshi</dc:creator>
      <pubDate>Wed, 05 Feb 2025 06:42:52 +0000</pubDate>
      <link>https://dev.to/himanshu_joshi_d4c8a0fad3/dsa-problem-1-determine-if-two-numbers-add-up-to-a-target-value-php-4flb</link>
      <guid>https://dev.to/himanshu_joshi_d4c8a0fad3/dsa-problem-1-determine-if-two-numbers-add-up-to-a-target-value-php-4flb</guid>
      <description>&lt;p&gt;Given two unique integer arrays $a and $b, and an integer target value $v, create a function to determine whether there is a pair of numbers that add up to the target value $v, where one number comes from one array $a and the other comes from the second array $b. Return true if there is a pair that adds up to the target value; otherwise, return false.&lt;/p&gt;

&lt;p&gt;Examples&lt;/p&gt;

&lt;p&gt;sumOfTwo([1, 2], [4, 5, 6], 5) ➞ true&lt;/p&gt;

&lt;p&gt;sumOfTwo([1, 2], [4, 5, 6], 8) ➞ true&lt;/p&gt;

&lt;p&gt;sumOfTwo([1, 2], [4, 5, 6], 3) ➞ false&lt;/p&gt;

&lt;p&gt;sumOfTwo([1, 2], [4, 5, 6], 9) ➞ false&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php 
function sumOfTwo($arr1, $arr2, $element) {
    // Convert arr1 into a hash set for quick lookups
    $set = array_flip($arr1);  // array_flip converts values into keys

    foreach ($arr2 as $val) {
        $complement = $element - $val;
        if (isset($set[$complement])) {  // Faster lookup
            return true;  // Return immediately if found
        }
    }
    return false;
}

// Test cases
echo  (sumOfTwo([1, 2], [4, 5, 6], 5) ? "true" : "false");
echo (sumOfTwo([1, 2], [4, 5, 6], 8) ? "true" : "false");
echo (sumOfTwo([1, 2], [4, 5, 6], 3) ? "true" : "false");
echo (sumOfTwo([1, 2], [4, 5, 6], 9) ? "true" : "false");
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>programming</category>
      <category>dsa</category>
      <category>php</category>
    </item>
  </channel>
</rss>
