<?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: Think1s</title>
    <description>The latest articles on DEV Community by Think1s (@learndaily1).</description>
    <link>https://dev.to/learndaily1</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%2F473410%2F45e34cf3-de8f-45bf-a4ac-e6af31304c80.png</url>
      <title>DEV Community: Think1s</title>
      <link>https://dev.to/learndaily1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/learndaily1"/>
    <language>en</language>
    <item>
      <title>JS Interview Question #4</title>
      <dc:creator>Think1s</dc:creator>
      <pubDate>Thu, 04 May 2023 18:52:11 +0000</pubDate>
      <link>https://dev.to/learndaily1/js-interview-question-4-134f</link>
      <guid>https://dev.to/learndaily1/js-interview-question-4-134f</guid>
      <description>&lt;p&gt;Read more articles in &lt;a href="http://www.think1s.in"&gt;Think1s&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What will be the output of the following code?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;for (var i = 0; i &amp;lt; 5; i++) {&lt;br&gt;
  setTimeout(() =&amp;gt; {&lt;br&gt;
    console.log(i);&lt;br&gt;
  }, 0);&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
The output of the code will be:&lt;br&gt;
5&lt;br&gt;
5&lt;br&gt;
5&lt;br&gt;
5&lt;br&gt;
5&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Explanation:&lt;/p&gt;

&lt;p&gt;For each iteration, a setTimeout method is called, which takes a callback function that logs the current value of i to the console.&lt;/p&gt;

&lt;p&gt;However, since setTimeout is an asynchronous function, it does not execute immediately. Instead, it schedules the callback function to execute after a certain amount of time. In this case, the amount of time is set to 0, which means the callback function is scheduled to execute as soon as possible, but not immediately.&lt;/p&gt;

&lt;p&gt;Therefore, when the for loop finishes executing, the value of i will be 5. This means that all five setTimeout functions will execute their callback function with i equal to 5, resulting in the output of 5 printed five times to the console.&lt;/p&gt;

&lt;p&gt;Read more articles in &lt;a href="http://www.think1s.in"&gt;Think1s&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>interview</category>
    </item>
    <item>
      <title>JS Interview Question #3 (Polyfill for array.flat())</title>
      <dc:creator>Think1s</dc:creator>
      <pubDate>Thu, 02 Jun 2022 04:15:53 +0000</pubDate>
      <link>https://dev.to/learndaily1/js-interview-question-3-polyfill-for-arrayflat-4hp3</link>
      <guid>https://dev.to/learndaily1/js-interview-question-3-polyfill-for-arrayflat-4hp3</guid>
      <description>&lt;p&gt;Read more articles in &lt;a href="https://think1s.com"&gt;Think1s&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]]]];&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;flatArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;concat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;flatArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;curr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
          &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&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;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flatArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;Infinity&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click here &lt;a href="https://www.think1s.com/2022/02/javascript-qa-series-3.html"&gt;Object flattening&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Read more articles in &lt;a href="https://think1s.com"&gt;Think1s&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>JS Interview Question #2 (Accidental Global Variable)</title>
      <dc:creator>Think1s</dc:creator>
      <pubDate>Tue, 22 Mar 2022 03:21:46 +0000</pubDate>
      <link>https://dev.to/learndaily1/js-interview-question-2-accidental-global-variable-4fjb</link>
      <guid>https://dev.to/learndaily1/js-interview-question-2-accidental-global-variable-4fjb</guid>
      <description>&lt;p&gt;Visit &lt;a href="https://think1s.com"&gt;think1s&lt;/a&gt; to get more such questions.&lt;/p&gt;

&lt;p&gt;Revise Accidental Global Variable concepts to answer this questions.&lt;/p&gt;

&lt;p&gt;What is the output the following code?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function getNumber() {
        var a = b = 2;
        a++;
        return a;
      }
      console.log(typeof a);
      console.log(typeof b);

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

&lt;/div&gt;



&lt;p&gt;To know the answer &lt;a href="https://think1s.com"&gt;click here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What is the output the following code?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function getNumber() {
        var a = b = 2;
        a++;
        return a;
      }
      getNumber();
      console.log(typeof a);
      console.log(typeof b);

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

&lt;/div&gt;



&lt;p&gt;To know the answer &lt;a href="https://think1s.com"&gt;click here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>JS Interview Question #1 (Group Anagrams)</title>
      <dc:creator>Think1s</dc:creator>
      <pubDate>Sun, 20 Mar 2022 03:30:12 +0000</pubDate>
      <link>https://dev.to/learndaily1/js-interview-question-1-group-anagrams-22j4</link>
      <guid>https://dev.to/learndaily1/js-interview-question-1-group-anagrams-22j4</guid>
      <description>&lt;p&gt;Read more articles in &lt;a href="http://www.think1s.in"&gt;Think1s&lt;/a&gt;&lt;br&gt;
What is Anagram?&lt;br&gt;
According to wikipedia Anagram is a word, phrase, or name formed by rearranging the letters of another.&lt;br&gt;
Ex: Elbow and below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let groupAnagramsObj = {};
  for (let i of distinctArrSet) {
    let groupArr = sortedArr.reduce((acc, curr, index) =&amp;gt; {
      if (curr == i) {
        acc.push(index);
      }
      return acc;
    }, []);
    groupAnagramsObj[i] = groupArr;
  }

  // console.log(groupAnagramsObj)
  // { "below": [ 0, 1 ], "ceersu": [ 2, 3 ], "act": [ 4, 5, 6 ] }

  let anagramsGroup = [];
  for (let i in groupAnagramsObj) {
    anagramsGroup.push(groupAnagramsObj[i].map((item) =&amp;gt; arr[item]));
  }
  return anagramsGroup;
};
console.log(
  groupAnagrams(["elbow", "rescue", "cat", "secure", "act", "below", "tac"])
);

// [["below","elbow"],["secure","rescue"],["cat","act","tac"]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read more articles in &lt;a href="https://think1s.com"&gt;Think1s&lt;/a&gt;&lt;/p&gt;

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