<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[codebrewer]]></title><description><![CDATA[I’m a software developer who is skilled and passionate about innovation and collaboration. I love hiking, traveling, and embracing new experiences that fuel my ]]></description><link>https://blog.varunjoshi.co.in</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1618656031762/_d3GuyDGF.png</url><title>codebrewer</title><link>https://blog.varunjoshi.co.in</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 00:58:15 GMT</lastBuildDate><atom:link href="https://blog.varunjoshi.co.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How we reproduced an iOS Firefox only bug without an iPhone ]]></title><description><![CDATA[Oh, the glamour of frontend engineering chasing pixels across screens while battling invisible gremlins
BackStory

your app works flawlessly on desktop Chrome, kinda sorta on Android, but explodes int]]></description><link>https://blog.varunjoshi.co.in/how-we-reproduced-an-ios-firefox-only-bug-without-an-iphone</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/how-we-reproduced-an-ios-firefox-only-bug-without-an-iphone</guid><category><![CDATA[#user-agent]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[debugging]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[webdev]]></category><category><![CDATA[devtools]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Sat, 07 Mar 2026 15:26:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/5ffdc71dc162d710c9b12cfb/3a89076c-e1fc-4161-8bc3-af20d04166fe.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Oh, the glamour of frontend engineering chasing pixels across screens while battling invisible gremlins</p>
<h3>BackStory</h3>
<blockquote>
<p>your app works flawlessly on desktop Chrome, kinda sorta on Android, but explodes into a caching catastrophe on iOS Safari. Sound familiar? That's exactly what bit me during a recent debugging marathon. We were simulating iOS environments, only to unearth ancient legacy logic that treated API responses like a <code>choose your own adventure</code> book based on...</p>
</blockquote>
<p>Spoiler: it introduced sneaky inconsistencies that made our "responsive" design look like a bad magic trick. Buckle up, because this post dives into how user agent-based debugging saved the day, and why it's a double-edged sword</p>
<h2><strong>What is a user agent?</strong></h2>
<p>The user agent, often shortened to UA, is an HTTP request header that says what browser, engine, OS, and sometimes device is making the request. Example:</p>
<p><code>Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1</code></p>
<p>Browsers also expose this string client side as <code>navigator.userAgent</code>. Newer APIs expose structured data via <code>navigator.userAgentData</code> where supported.</p>
<p>Why you should treat user agent data with suspicion</p>
<ul>
<li><p>It is easy to spoof.</p>
</li>
<li><p>Browser vendors change the format for privacy.</p>
</li>
<li><p>It contains lots of historical cruft, making regex detection fragile.</p>
</li>
<li><p>Relying on it for core logic creates brittle branches that are hard to test and maintain.</p>
</li>
</ul>
<h2>Simulating the Beast: DevTools to the Rescue</h2>
<p>We went to finding solution on how we could debug this on a specific browser on a device, tried BrowserStack ,but it didn't help because we were looking for firefox on ios device<br />Can't afford a device farm? No problem. Modern dev tools let you override UAs like a pro, exposing those hidden branches without touching hardware.</p>
<p>Here's a dead simple way to spoof an iPhone UA in Chrome DevTools runnable right now:</p>
<pre><code class="language-javascript">// Open DevTools &gt; Network &gt; Network conditions &gt; Custom user agent
// Paste this iPhone 14 Pro Max UA (real-world example)
const iOSUA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1';

// Test it in console:
console.log(navigator.userAgent.includes('iPhone')); // true after override
</code></pre>
<p><strong>Step by step breakdown</strong>:</p>
<ol>
<li><p>Fire up DevTools (F12), hit Network tab.</p>
</li>
<li><p>Click "More network conditions" (or Cmd+Shift+P &gt; "Network conditions").</p>
</li>
<li><p>Uncheck "Use browser default," paste the UA, done.</p>
</li>
</ol>
<p>We did this in a Next.js app that simulates an iOS WebView. Suddenly, API calls skipped the cache on "mobile," but fetched stale data on desktop.</p>
<h3>How do we get this string</h3>
<p>A buried <code>isMobile()</code> function sniffing UA for iOS/Android, then helping us fix it:</p>
<pre><code class="language-javascript">// DON'T DO THIS Classic legacy trash
function isMobile(ua = navigator.userAgent) {
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua);
}

// Detect Firefox on iPhone
function isFirefoxOniPhone(ua = navigator.userAgent) {
  return /iPhone/i.test(ua) &amp;&amp; /FxiOS/i.test(ua);
}

// simple api call we want on iphone to help us get some data 
function fetchData(url) {
  const ua = navigator.userAgent;

  // Special case: Firefox on iPhone
  if (isFirefoxOniPhone(ua)) {
    console.log("Firefox on iPhone detected");
    return fetch(url).then(res =&gt; res.json());
  }
}

console.log(fetchData(www.example.com))
</code></pre>
<h2>Why User Agent Spoofing Helped Us Debug the Logic</h2>
<p>In our case, the issue wasn’t really about caching or Safari itself, it was about <strong>code paths that depended on the browser environment</strong>.</p>
<p>Modern applications often contain conditional logic like this:</p>
<pre><code class="language-plaintext">if (isMobile()) {
  bypassCache();
}
</code></pre>
<p>The problem is that these branches only execute <strong>under specific environments</strong>. If you’re testing on desktop Chrome, that part of the code may never run.</p>
<p>By overriding the <strong>User Agent string</strong>, we essentially tricked the application into believing it was running on a different device, in this case an iPhone browser.</p>
<p>Once the browser reported itself as iOS, our application started executing the <strong>mobile-specific code path</strong>, which immediately exposed the hidden logic responsible for the inconsistent behavior.</p>
<p>In other words, UA spoofing allowed us to:</p>
<ul>
<li><p><strong>Reproduce a device-specific environment</strong></p>
</li>
<li><p><strong>Trigger code paths that normally wouldn’t run on our machine</strong></p>
</li>
<li><p><strong>Observe how the application behaves under those conditions</strong></p>
</li>
</ul>
<p>Without it, we would have needed a physical device or a remote testing environment to reproduce the issue.</p>
<hr />
<h2>The Real Lesson</h2>
<p>User agent sniffing is often considered a fragile practice for production logic, but it can still be a <strong>powerful debugging technique</strong>.</p>
<p>It allows developers to simulate:</p>
<ul>
<li><p>different devices</p>
</li>
<li><p>different browsers</p>
</li>
<li><p>different environments</p>
</li>
</ul>
<p>and verify how their application responds.</p>
<p>In our case, the browser wasn’t the real problem; <strong>The assumptions inside our code were</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[JavaScript Ambiguity]]></title><description><![CDATA[Introduction
JavaScript is the only language that will look you in the eye, say "yes, that's valid," and then silently ruin your production build. Every other language would throw an error or refuse to compile - but JavaScript? It coerces types, lies...]]></description><link>https://blog.varunjoshi.co.in/javascript-ambiguity</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/javascript-ambiguity</guid><category><![CDATA[#js-interview]]></category><category><![CDATA[js]]></category><category><![CDATA[JS Tricks]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Fri, 19 Dec 2025 15:10:19 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1766156845072/5afe91d9-0de1-4257-9f23-c4f88544fa98.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>JavaScript is the only language that will look you in the eye, say "yes, that's valid," and then silently ruin your production build. Every other language would throw an error or refuse to compile - but JavaScript? It coerces types, lies about typeof results, and changes this binding based on invisible rules</p>
<h2 id="heading-the-typeof-operators-big-lies">The typeof Operator's Big Lies</h2>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> [])
<span class="hljs-comment">// Returns "object"</span>

<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> {})
<span class="hljs-comment">// Returns "object"</span>

<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> Nan)
<span class="hljs-comment">// Despite being "Not-A-Number"</span>

<span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">typeof</span> <span class="hljs-literal">null</span>)
<span class="hljs-comment">// Returns "object"</span>
</code></pre>
<p>JavaScript's typeof operator lies blatantly about arrays. An empty array [] is not an object, but typeof [] returns "object" because arrays inherit from Object.prototype. This historical bug from JavaScript's early days trips up developers constantly, same like typeof {}.</p>
<p>Even worse, typeof null returns "object" despite null being a primitive value. This dates back to JavaScript's original implementation where null had an object type tag that was never fixed for backward compatibility.</p>
<h2 id="heading-array-or-object">Array or Object</h2>
<p>The real way to check arrays is Array.isArray([]), which returns true.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isArrayOrObject</span>(<span class="hljs-params">value</span>) </span>{
    <span class="hljs-keyword">if</span> (value === <span class="hljs-literal">null</span> || <span class="hljs-keyword">typeof</span> value !== <span class="hljs-string">'object'</span>) {
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    }
    <span class="hljs-keyword">return</span> <span class="hljs-built_in">Array</span>.isArray(value) || <span class="hljs-built_in">Object</span>.prototype.toString.call(value) === <span class="hljs-string">'[object Object]'</span>;
}

The real way to check arrays is <span class="hljs-built_in">Array</span>.isArray([]), which returns <span class="hljs-literal">true</span>.
</code></pre>
<h2 id="heading-string-conversion-gotchas">String Conversion Gotchas</h2>
<p>JavaScript loves implicit toString() calls during concatenation.</p>
<pre><code class="lang-javascript"><span class="hljs-number">42</span> + <span class="hljs-string">"0"</span> <span class="hljs-comment">// 420</span>
[] + {}  <span class="hljs-comment">// "[object Object]" </span>
<span class="hljs-literal">null</span> + <span class="hljs-string">""</span> <span class="hljs-comment">// null</span>
</code></pre>
<p>Number becomes "420" because + coerces the number to string first. But becomes [] + {} becomes "[object Object]" because array toString() joins elements (empty so nothing) and object falls back to default toString.</p>
<blockquote>
<p>null + "" is "null", undefined + "" is "undefined".</p>
</blockquote>
<h2 id="heading-the-deadly-aa-expression">The Deadly a++a Expression</h2>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> a = <span class="hljs-string">"1"</span>; 
<span class="hljs-built_in">console</span>.log(a+ +a); 

<span class="hljs-built_in">console</span>.log((<span class="hljs-string">'b'</span> + <span class="hljs-string">'a'</span> + +<span class="hljs-string">'a'</span>+<span class="hljs-string">'a'</span>).toLowerCase());
<span class="hljs-comment">// guess the output</span>
</code></pre>
<h2 id="heading-truthy-and-falsy-ambush-list">Truthy and Falsy Ambush List</h2>
<pre><code class="lang-javascript">textif([]) <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"truthy!"</span>);  <span class="hljs-comment">// This runs</span>
!![] === <span class="hljs-literal">true</span>                   <span class="hljs-comment">// true</span>
!!<span class="hljs-number">0</span> === <span class="hljs-literal">false</span>                   <span class="hljs-comment">// true</span>
</code></pre>
<blockquote>
<p>Double negation !! value coerces anything to proper boolean: !![] is true, !!0 is false.</p>
</blockquote>
<p>Only 6 falsy values exist:</p>
<p><code>false, 0, "", null, undefined, NaN.</code></p>
<p>Everything else is truthy, including [] (empty array), {} (empty object), "false" (string), and Infinity.</p>
<h2 id="heading-this-keyword-the-shape-shifter">this Keyword: The Shape-Shifter</h2>
<p>Regular functions get dynamic this based on the call site. Arrow functions capture lexical this from the surrounding scope.</p>
<pre><code class="lang-javascript">textfunction Regular() {
  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{ 
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>);  <span class="hljs-comment">// window/global</span>
  }, <span class="hljs-number">0</span>); 
}

<span class="hljs-keyword">const</span> Arrow = <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> { 
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>);  <span class="hljs-comment">// Arrow's lexical this</span>
  }, <span class="hljs-number">0</span>); 
};

Regular.call({<span class="hljs-attr">x</span>:<span class="hljs-number">1</span>});  <span class="hljs-comment">// logs window</span>
Arrow.call({<span class="hljs-attr">x</span>:<span class="hljs-number">1</span>});    <span class="hljs-comment">// logs {x:1} if called in object method</span>
</code></pre>
<h2 id="heading-function-definitions-compared">Function Definitions Compared</h2>
<ul>
<li><p><strong>function declarations</strong> hoist completely (name + body movable to top)</p>
</li>
<li><p><strong>function expressions</strong> hoist only declaration (body undefined until assignment)</p>
</li>
<li><p><strong>Arrow functions</strong> are always expressions, no hoisting, no own this/arguments</p>
</li>
</ul>
<pre><code class="lang-javascript">textgreet();           <span class="hljs-comment">// Works - fully hoisted</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params"></span>) </span>{ <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hi"</span>); }

<span class="hljs-built_in">console</span>.log(fn);   <span class="hljs-comment">// undefined</span>
<span class="hljs-keyword">var</span> fn = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{};

sayHi();           <span class="hljs-comment">// ReferenceError - TDZ</span>
<span class="hljs-keyword">const</span> sayHi = <span class="hljs-function">() =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Hi"</span>);
</code></pre>
<h2 id="heading-bonus-production-killers">Bonus Production Killers</h2>
<pre><code class="lang-javascript">textNaN !== <span class="hljs-literal">NaN</span>                    <span class="hljs-comment">// true - use Number.isNaN()</span>
+[] === <span class="hljs-number">0</span>                          <span class="hljs-comment">// true</span>
+![] === <span class="hljs-number">1</span>                         <span class="hljs-comment">// true</span>
{} + [] === <span class="hljs-string">"[object Object]"</span>      <span class="hljs-comment">// true  </span>
[] + {} === <span class="hljs-string">""</span>                     <span class="hljs-comment">// true</span>
<span class="hljs-built_in">JSON</span>.stringify({<span class="hljs-attr">a</span>: <span class="hljs-literal">undefined</span>})     <span class="hljs-comment">// "{}" - drops undefined properties</span>
</code></pre>
<hr />
<h2 id="heading-the-escape-plan">The Escape Plan</h2>
<p>JavaScript doesn't break your code with errors - it transforms it into something subtly wrong that passes tests until production. Use TypeScript for safety, ESLint with strict rules, and always test edge cases. Your future self will thank you.</p>
]]></content:encoded></item><item><title><![CDATA[How I Built EduAgent: 30-Minute MVP Guide]]></title><description><![CDATA[Introduction
EduAgent is a lightweight AI teaching assistant designed to help educators and learners quickly generate study notes, flashcards, and quizzes from any learning material. Built in just thirty minutes, this MVP shows how easy it is to harn...]]></description><link>https://blog.varunjoshi.co.in/how-i-built-eduagent-30-minute-mvp-guide</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/how-i-built-eduagent-30-minute-mvp-guide</guid><category><![CDATA[agentic AI]]></category><category><![CDATA[agents in ai]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Tue, 18 Nov 2025 10:29:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/2EJCSULRwC8/upload/fed5089e7d1e150a5e2baec25c9914a1.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>EduAgent is a lightweight AI teaching assistant designed to help educators and learners quickly generate study notes, flashcards, and quizzes from any learning material. Built in just thirty minutes, this MVP shows how easy it is to harness modern APIs and frontend frameworks to automate critical education workflows.</p>
<h2 id="heading-what-well-cover">What We’ll Cover</h2>
<ul>
<li><p>Project overview and goals</p>
</li>
<li><p>Core features of EduAgent</p>
</li>
<li><p>Step-by-step walkthrough on the build using Lyzr</p>
</li>
<li><p>Key takeaways for rapid MVP development</p>
</li>
</ul>
<h2 id="heading-steps-used">Steps Used</h2>
<h2 id="heading-1-defining-the-products-purpose">1. Defining the Product’s Purpose</h2>
<p>Start by listing what EduAgent can do</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763458688228/b5ef8d30-e893-4dbf-a9f6-80840bc4ba5e.png" alt class="image--center mx-auto" /></p>
<p>This clarity saves build time and guides every decision.​</p>
<h2 id="heading-2-building-using-lyzr-api">2. Building using LYZR API</h2>
<ul>
<li><p>Steps to Login to Lyzr Agent Studio</p>
<ul>
<li><p>Go to <a target="_blank" href="https://studio.lyzr.ai/.%E2%80%8B"><strong>https://studio.lyzr.ai/</strong></a></p>
</li>
<li><p>Click "Sign Up" and choose Google, LinkedIn, GitHub, or enter your email.​</p>
</li>
<li><p>Complete the sign-up and verify your email if prompted.​</p>
</li>
<li><p>If you already have an account, click "Login" and enter your credentials.​</p>
</li>
</ul>
</li>
</ul>
<hr />
<h2 id="heading-steps-to-create-a-single-agent">Steps to Create a Single Agent</h2>
<ol>
<li><p>After logging in, find the sidebar and click on the <a target="_blank" href="https://studio.lyzr.ai/">"</a>Agents" section or "Agent Builder".​</p>
</li>
<li><p>Select “New Agent” or “+ Build Agent” to begin.​</p>
</li>
<li><p>Enter basic details:</p>
<ul>
<li><p>Name: Give your agent a name</p>
</li>
<li><p>Description: Briefly describe what your agent does.​</p>
</li>
</ul>
</li>
<li><p>Choose an LLM model from the provided list; adjust parameters if needed.</p>
</li>
<li><p>Define the agent’s role and instructions (what you want the agent to do, e.g., create notes, answer questions).​</p>
</li>
<li><p>(Optional) Attach any knowledge sources relevant to your agent—such as PDFs, web URLs, databases, or spreadsheets.​</p>
</li>
<li><p>Add features or built-in tools as needed (optional for advanced <a target="_blank" href="https://studio.lyzr.ai/">scenarios).​</a></p>
</li>
<li><p>Click "Create" to finalize your agent. It is ready for testing.​</p>
</li>
<li><p>Grab your API key.</p>
</li>
<li><p>Write functions to:</p>
<ul>
<li><p>Send uploads to LYZR API (content extraction, transcription)</p>
</li>
<li><p>Fetch outputs: explanations, notes, flashcards, quizzes​</p>
</li>
</ul>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763461271003/578b779e-4528-4e71-8f3b-2bfecd118d97.jpeg" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763461420137/1aa42390-a513-4662-9777-cf64f15222de.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-2-setting-up-the-frontend">2. Setting Up the Frontend</h2>
<p>Spin up a React app using a boilerplate tool like Create React App or Vite. Build UX components for content upload (text, PDF, video) and results display panels—for fast functionality and easy testing.​</p>
<ul>
<li><p>POST data to LYZR endpoints and handle API responses in your React state.</p>
</li>
<li><p>Add basic styles for readability.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763461568166/2797c876-bb92-4f60-aafb-1989461b3114.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763461595141/3f4b32c5-ca1b-4e37-acd5-ff361438ee95.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In half an hour, you can build a working MVP for an AI-powered teaching assistant using React and LYZR API. By focusing on the essential user workflow upload, analyze, and get actionable study aids, you can move from concept to demo faster than ever. EduAgent is proof that quality education automation is only a few lines of code away.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/2HGJnz-ooNc?si=XWHJG4ZmLq69MNuC">https://youtu.be/2HGJnz-ooNc?si=XWHJG4ZmLq69MNuC</a></div>
]]></content:encoded></item><item><title><![CDATA[Mastering JavaScript's Map]]></title><description><![CDATA[Introduction
Objects have long been the go-to choice for storing key-value pairs in JavaScript. However, the Map data structure offers a more powerful and flexible alternative. Unlike objects, Map allows keys of any data type, maintains insertion ord...]]></description><link>https://blog.varunjoshi.co.in/mastering-javascripts-map</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/mastering-javascripts-map</guid><category><![CDATA[js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Redis]]></category><category><![CDATA[maps in javaScript]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Tue, 18 Feb 2025 15:12:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739891346922/beb2e127-1995-4925-a792-ea22278d218c.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Objects have long been the go-to choice for storing key-value pairs in JavaScript. However, the <code>Map</code> data structure offers a more powerful and flexible alternative. Unlike objects, <code>Map</code> allows keys of any data type, maintains insertion order, and performs better in some cases.</p>
<p>In this guide, you'll learn everything about <code>Map</code> JavaScript, including how to use it effectively in real-world scenarios.</p>
<hr />
<h2 id="heading-what-is-a-map">What is a Map?</h2>
<p>A <code>Map</code> is a built-in JavaScript data structure that holds key-value pairs, where keys can be <strong>any type of value</strong>, including objects, functions, and primitive types.</p>
<h3 id="heading-why-use-map-over-object">Why Use Map Over Object?</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Map</td><td>Object</td></tr>
</thead>
<tbody>
<tr>
<td>Key Types</td><td>Any (objects, functions, etc.)</td><td>Strings or symbols only</td></tr>
<tr>
<td>Order</td><td>Maintains insertion order</td><td>No guaranteed order</td></tr>
<tr>
<td>Size Property</td><td><code>.size</code></td><td>Must use <code>Object.keys(obj).length</code></td></tr>
<tr>
<td>Performance</td><td>Faster for frequent additions/removals</td><td>Slower when handling large key-value sets</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-creating-a-map">Creating a Map</h2>
<p>You can create a <code>Map</code> using the <code>new Map()</code> constructor:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> myMap = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();
</code></pre>
<h3 id="heading-adding-key-value-pairs">Adding Key-Value Pairs</h3>
<p>Use <code>.set(key, value)</code> to add entries:</p>
<pre><code class="lang-js">myMap.set(<span class="hljs-string">'name'</span>, <span class="hljs-string">'Alice'</span>);
myMap.set(<span class="hljs-number">42</span>, <span class="hljs-string">'The Answer'</span>);
myMap.set(<span class="hljs-literal">true</span>, <span class="hljs-string">'Boolean Key'</span>);
</code></pre>
<h3 id="heading-accessing-values">Accessing Values</h3>
<p>Retrieve values using <code>.get(key)</code>, ensuring you use the exact key reference:</p>
<pre><code class="lang-js"><span class="hljs-built_in">console</span>.log(myMap.get(<span class="hljs-string">'name'</span>)); <span class="hljs-comment">// Alice</span>
<span class="hljs-built_in">console</span>.log(myMap.get(<span class="hljs-number">42</span>)); <span class="hljs-comment">// The Answer</span>
</code></pre>
<h3 id="heading-checking-key-existence">Checking Key Existence</h3>
<p>Use <code>.has(key)</code> to check if a key exists:</p>
<pre><code class="lang-js"><span class="hljs-built_in">console</span>.log(myMap.has(<span class="hljs-string">'name'</span>)); <span class="hljs-comment">// true</span>
<span class="hljs-built_in">console</span>.log(myMap.has(<span class="hljs-string">'age'</span>)); <span class="hljs-comment">// false</span>
</code></pre>
<h3 id="heading-removing-a-key">Removing a Key</h3>
<p>Delete a key-value pair using <code>.delete(key)</code>:</p>
<pre><code class="lang-js">myMap.delete(<span class="hljs-number">42</span>);
<span class="hljs-built_in">console</span>.log(myMap.has(<span class="hljs-number">42</span>)); <span class="hljs-comment">// false</span>
</code></pre>
<h3 id="heading-finding-the-size">Finding the Size</h3>
<p>Use <code>.size</code> to get the number of elements:</p>
<pre><code class="lang-js"><span class="hljs-built_in">console</span>.log(myMap.size); <span class="hljs-comment">// 2</span>
</code></pre>
<hr />
<h2 id="heading-iterating-over-a-map">Iterating Over a Map</h2>
<p>You can loop through a <code>Map</code> using different methods:</p>
<h3 id="heading-using-foreach">Using <code>forEach()</code></h3>
<pre><code class="lang-js">myMap.forEach(<span class="hljs-function">(<span class="hljs-params">value, key</span>) =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${key}</span> -&gt; <span class="hljs-subst">${value}</span>`</span>);
});
</code></pre>
<h3 id="heading-using-forof">Using <code>for...of</code></h3>
<pre><code class="lang-js"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> [key, value] <span class="hljs-keyword">of</span> myMap) {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${key}</span> -&gt; <span class="hljs-subst">${value}</span>`</span>);
}
</code></pre>
<h3 id="heading-converting-map-to-array">Converting Map to Array</h3>
<p>If you need an array representation:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> entriesArray = <span class="hljs-built_in">Array</span>.from(myMap);
<span class="hljs-built_in">console</span>.log(entriesArray);
</code></pre>
<hr />
<h2 id="heading-using-arrays-or-objects-as-keys">Using Arrays or Objects as Keys</h2>
<p>Unlike objects, <code>Map</code> allows arrays and objects as keys:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> myMap = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();
<span class="hljs-keyword">const</span> keyArray = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
myMap.set(keyArray, <span class="hljs-string">'Array as Key'</span>);

<span class="hljs-built_in">console</span>.log(myMap.get(keyArray)); <span class="hljs-comment">// Array as Key ✅</span>
</code></pre>
<p><strong>Important Note:</strong> If you try to retrieve the value using a new array (<code>myMap.get([1, 2, 3])</code>), it won’t work because objects and arrays are <strong>reference-based</strong>, not value-based.</p>
<hr />
<h2 id="heading-clearing-a-map">Clearing a Map</h2>
<p>Use <code>.clear()</code> to remove all key-value pairs:</p>
<pre><code class="lang-js">myMap.clear();
<span class="hljs-built_in">console</span>.log(myMap.size); <span class="hljs-comment">// 0</span>
</code></pre>
<hr />
<h2 id="heading-real-world-use-cases">Real-World Use Cases</h2>
<h3 id="heading-1-caching-computation-results">1. <strong>Caching Computation Results</strong></h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> myMap = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();

<span class="hljs-keyword">const</span> getSumofArray = <span class="hljs-function">(<span class="hljs-params">...arr</span>) =&gt;</span> {
    <span class="hljs-keyword">if</span> (myMap.has(arr)) <span class="hljs-keyword">return</span> myMap.get(arr);

    <span class="hljs-keyword">let</span> computeSum = arr.reduce(<span class="hljs-function">(<span class="hljs-params">initialValue, accum</span>) =&gt;</span> initialValue + accum, <span class="hljs-number">0</span>);
    myMap.set(arr, computeSum); <span class="hljs-comment">//we can store arr as the key</span>
    <span class="hljs-keyword">return</span> computeSum;
};

<span class="hljs-built_in">console</span>.time(<span class="hljs-string">"Function Execution Time"</span>);
<span class="hljs-built_in">console</span>.log(getSumofArray(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>));
<span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">"Function Execution Time"</span>);

<span class="hljs-built_in">console</span>.time(<span class="hljs-string">"Function Execution Time"</span>);
<span class="hljs-built_in">console</span>.log(getSumofArray(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>));
<span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">"Function Execution Time"</span>);

<span class="hljs-built_in">console</span>.time(<span class="hljs-string">"Function Execution Time"</span>);
<span class="hljs-built_in">console</span>.log(getSumofArray(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>));
<span class="hljs-built_in">console</span>.timeEnd(<span class="hljs-string">"Function Execution Time"</span>);

<span class="hljs-comment">/***
output
15
Function Execution Time: 74.399ms
13
Function Execution Time: 0.078ms
15
Function Execution Time: 0.087ms

=== Code Execution Successful ===
**/</span>
</code></pre>
<p>Using <code>Map</code> to cache computed values can speed up repeated function calls:</p>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<p>The <code>Map</code> data structure in JavaScript is a <strong>powerful alternative to objects</strong> for handling key-value pairs. It offers flexibility, better performance, and maintains insertion order. Whether you're working with <strong>complex keys (objects/arrays), tracking data efficiently, or improving performance</strong>, <code>Map</code> is a great choice.</p>
<p><strong>What’s your favorite use case for Map? Let me know in the comments!</strong> 🚀</p>
]]></content:encoded></item><item><title><![CDATA[Binary Array Segregation]]></title><description><![CDATA[In this blog, we’ll explore a JavaScript function that manipulates an array using the two-pointer technique. The function, named twoSum, is designed to reorder elements in an array based on specific conditions. Let’s dive into its implementation, fun...]]></description><link>https://blog.varunjoshi.co.in/binary-array-segregation</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/binary-array-segregation</guid><category><![CDATA[Programming Blogs]]></category><category><![CDATA[Competitive programming]]></category><category><![CDATA[js]]></category><category><![CDATA[two pointers]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Thu, 16 Jan 2025 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/4Ennrbj1svk/upload/493fc624592c3e8917c5cf4ca6aa5f1a.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this blog, we’ll explore a JavaScript function that manipulates an array using the two-pointer technique. The function, named <code>twoSum</code>, is designed to reorder elements in an array based on specific conditions. Let’s dive into its implementation, functionality, and the underlying logic.</p>
<h4 id="heading-the-problem-statement">The Problem Statement</h4>
<p>Given an array <code>nums</code> consisting of binary values (0s and 1s), rearrange the array so that all zeros appear on the left and all ones appear on the right. The function should do this in-place without using extra space, and it should return the modified array.</p>
<h5 id="heading-input">Input:</h5>
<ul>
<li><code>nums</code>: An array of integers consisting only of 0s and 1s.</li>
</ul>
<h5 id="heading-output">Output:</h5>
<ul>
<li>A reordered array where all 0s are moved to the left and all 1s to the right.</li>
</ul>
<h5 id="heading-example">Example:</h5>
<p>Input</p>
<h5 id="heading-nums-0-1-1-0-1-0-0"><code>nums = [0, 1, 1, 0, 1, 0, 0]</code></h5>
<p>Output<br /><code>[0, 0, 0, 0, 1, 1, 1]</code></p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">var</span> twoSum = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">nums</span>)</span>{
      <span class="hljs-keyword">let</span> len = nums.length
      start = <span class="hljs-number">0</span>;
      end = nums.length <span class="hljs-number">-1</span>;
      <span class="hljs-keyword">while</span>(start&lt;end){
          <span class="hljs-keyword">if</span>(nums[start]&gt;nums[end]){
             nums[start] = nums[start]+nums[end]
             nums[end]= nums[start] - nums[end]
             nums[start] = nums[start] - nums[end]
             start = start + <span class="hljs-number">1</span>
             end = end - <span class="hljs-number">1</span>
          }<span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(nums[start]+nums[end]&gt;<span class="hljs-number">0</span>){
              end = end <span class="hljs-number">-1</span>;
          }<span class="hljs-keyword">else</span>{
          start = start + <span class="hljs-number">1</span>
          }
      }
      <span class="hljs-keyword">return</span> nums
  }

   <span class="hljs-built_in">console</span>.log(twoSum ([<span class="hljs-number">0</span>,<span class="hljs-number">1</span>,<span class="hljs-number">1</span>,<span class="hljs-number">0</span>,<span class="hljs-number">1</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>]));

  <span class="hljs-comment">/*output [
    0, 0, 0, 0,
    1, 1, 1
  ] *?</span>
</code></pre>
<h4 id="heading-why-this-works">Why This Works</h4>
<p>The two-pointer technique ensures that the array is processed efficiently with a time complexity of <strong>O(n)</strong>. By using the conditions:</p>
<ul>
<li><p>The array is rearranged such that zeros are moved to the left.</p>
</li>
<li><p>Ones are shifted to the right without additional memory allocation or external libraries.</p>
</li>
</ul>
<h4 id="heading-a-closer-look-at-swapping">A Closer Look at Swapping</h4>
<p>The swapping logic avoids using a temporary variable by leveraging simple arithmetic:</p>
<ul>
<li><p><code>a = a + b</code></p>
</li>
<li><p><code>b = a - b</code></p>
</li>
<li><p><code>a = a - b</code></p>
</li>
</ul>
<p>This is a clever trick but should be used cautiously. If the numbers are large, there’s a risk of exceeding the number limits in JavaScript.</p>
<p><strong>When to Use This Pattern</strong></p>
<p>The two-pointer approach is useful for:</p>
<ul>
<li><p>Rearranging or partitioning arrays.</p>
</li>
<li><p>Finding pairs that meet specific criteria (e.g., sum, difference).</p>
</li>
<li><p>Problems involving sorted arrays.</p>
</li>
</ul>
<hr />
<p>Second Approach  </p>
<p>This approach counts the number of 1s and builds a new array accordingly.</p>
<p>Here’s the implementation of the <code>twoSumNew</code> function:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> twoSumNew = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">nums</span>)</span>{
    <span class="hljs-keyword">const</span> len = nums.length;
    <span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">let</span> newArray = [];
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>; i&lt;len;i++){
        <span class="hljs-keyword">if</span>(nums[i]==<span class="hljs-number">1</span>){
            sum += <span class="hljs-number">1</span>;
        }
    }
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span>; i&lt;len; i++){
        <span class="hljs-keyword">if</span>(i&lt;len-sum){
            newArray.push(<span class="hljs-number">0</span>)
        }<span class="hljs-keyword">else</span>{
            newArray.push(<span class="hljs-number">1</span>)
        }
    }
    <span class="hljs-keyword">return</span> newArray
}
</code></pre>
<h4 id="heading-explanation-of-the-code">Explanation of the Code</h4>
<ol>
<li><p><strong>Counting 1s:</strong> A <code>for</code> loop traverses the array and increments a <code>sum</code> variable for each <code>1</code> encountered. This gives the total number of 1s in the array.</p>
</li>
<li><p><strong>Building the New Array:</strong> Another <code>for</code> loop iterates through the array:</p>
<ul>
<li><p>If the current index is less than <code>len - sum</code>, it appends <code>0</code> to the new array.</p>
</li>
<li><p>Otherwise, it appends <code>1</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Return Statement:</strong> After constructing the new array, it is returned as the output.</p>
</li>
</ol>
<h3 id="heading-comparison-of-the-two-approaches">Comparison of the Two Approaches</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Two-Pointer Technique</td><td>Counting Mechanism</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Time Complexity</strong></td><td>O(n)</td><td>O(n)</td></tr>
<tr>
<td><strong>Space Complexity</strong></td><td>O(1) (in-place modification)</td><td>O(n) (new array creation)</td></tr>
<tr>
<td><strong>Ease of Implementation</strong></td><td>Moderate</td><td>Easy</td></tr>
<tr>
<td><strong>Use Case</strong></td><td>In-place modification needed</td><td>Original array not needed</td></tr>
</tbody>
</table>
</div><h3 id="heading-conclusion">Conclusion</h3>
<p>The <code>twoSum</code> function demonstrates how efficient array manipulation can be achieved using the two-pointer technique. Understanding the logic behind the swapping and condition checks helps in crafting similar solutions for other problems. Next time you encounter an array challenge, consider whether the two-pointer approach can simplify your solution!</p>
]]></content:encoded></item><item><title><![CDATA[Must-Know JavaScript One-Liners for Developers: Part 1]]></title><description><![CDATA[Reverse a string
  The split function helps us break a string into multiple individual elements, which can then be reversed and joined to a full string.


function isPalindrome(str) {
   return str === str.split('').reverse().join('');

}

// Example...]]></description><link>https://blog.varunjoshi.co.in/must-know-javascript-one-liners-for-developers-part-1</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/must-know-javascript-one-liners-for-developers-part-1</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[interview]]></category><category><![CDATA[coding]]></category><category><![CDATA[coding challenge]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Tue, 15 Oct 2024 04:48:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/iEiUITs149M/upload/f2bb45b8843a6a930d793322c908a638.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><h3 id="heading-reverse-a-string">Reverse a string</h3>
<p>  The <code>split</code> function helps us break a string into multiple individual elements, which can then be <code>reversed</code> and <code>joined</code> to a full string.</p>
</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isPalindrome</span>(<span class="hljs-params">str</span>) </span>{
   <span class="hljs-keyword">return</span> str === str.split(<span class="hljs-string">''</span>).reverse().join(<span class="hljs-string">''</span>);

}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-built_in">console</span>.log(isPalindrome(<span class="hljs-string">"racecar"</span>)); <span class="hljs-comment">// Output: true   // Output: false</span>
</code></pre>
<ul>
<li><h3 id="heading-removing-duplicates-from-an-array">R<strong>emoving Duplicates from an Array</strong></h3>
</li>
</ul>
<blockquote>
<p>Removing duplicates involves creating a new array that only contains unique elements.</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">removeDuplicates</span>(<span class="hljs-params">arr</span>) </span>{
    <span class="hljs-keyword">return</span> [...new <span class="hljs-built_in">Set</span>(arr)];
}

<span class="hljs-comment">// Example usage:</span>
<span class="hljs-built_in">console</span>.log(removeDuplicates([<span class="hljs-number">9</span>, <span class="hljs-number">2</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>])); 
<span class="hljs-comment">// Output: [9, 2, 3, 4, 5]</span>
</code></pre>
<ul>
<li><h3 id="heading-flattenarray">flattenArray</h3>
</li>
</ul>
<blockquote>
<p>flatten array can be directly done using the flat property of the array.</p>
</blockquote>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flattenArray</span>(<span class="hljs-params">arr</span>) </span>{
    <span class="hljs-keyword">return</span> arr.flat(<span class="hljs-literal">Infinity</span>);
}
<span class="hljs-comment">// Example usage:</span>
<span class="hljs-built_in">console</span>.log(flattenArray([<span class="hljs-number">1</span>, [<span class="hljs-number">2</span>, [<span class="hljs-number">3</span>, [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>]]]]));
</code></pre>
<p>That's it for today's brief read. More will be coming in the next parts, so stay tuned. Follow for more updates.</p>
]]></content:encoded></item><item><title><![CDATA[Leveraging Key Tags in List Mapping]]></title><description><![CDATA[In the realm of React development, efficiently managing lists is a common task, often accomplished using the map() function. While it might seem inconsequential at first glance, the judicious use of key tags during list mapping can significantly impa...]]></description><link>https://blog.varunjoshi.co.in/leveraging-key-tags-in-list-mapping</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/leveraging-key-tags-in-list-mapping</guid><category><![CDATA[React]]></category><category><![CDATA[keys]]></category><category><![CDATA[Mapping]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Sat, 02 Mar 2024 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/UYsBCu9RP3Y/upload/038be031428a39d18856c690f6b8cd61.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the realm of React development, efficiently managing lists is a common task, often accomplished using the <code>map()</code> function. While it might seem inconsequential at first glance, the judicious use of key tags during list mapping can significantly impact performance and maintainability in your codebase. In this article, we'll delve into the reasons why key tags should be applied specifically during list mapping and not within paragraph or div tags.</p>
<h3 id="heading-understanding-the-purpose-of-key-tags">Understanding the Purpose of Key Tags</h3>
<p>Before diving into the specifics, let's grasp the fundamental role of key tags in React. Key tags provide React with a unique identifier for each element in an array, facilitating efficient DOM updates during re-rendering. When components are re-rendered due to changes in state or props, React relies on these keys to determine which elements have been added, removed, or reordered within a list.</p>
<h3 id="heading-the-importance-of-key-tags-in-list-rendering">The Importance of Key Tags in List Rendering</h3>
<p>When rendering lists in React using the <code>map()</code> function, each iterated element should be assigned a unique key. This key acts as a marker for React to differentiate between list items, enabling it to optimize rendering performance. Without key tags, React may resort to inefficient methods, such as re-rendering the entire list, leading to suboptimal performance, especially with larger datasets.</p>
<h3 id="heading-why-key-tags-belong-in-list-mapping">Why Key Tags Belong in List Mapping</h3>
<ol>
<li><p><strong>Maintaining Component State</strong>: Placing key tags within the list mapping function ensures that each list item maintains its own internal state. This is crucial for components with dynamic behavior or user interactions, as it prevents unintended side effects caused by state misalignment.</p>
</li>
<li><p><strong>Optimizing Reconciliation</strong>: By assigning keys directly within the <code>map()</code> function, React can efficiently reconcile changes in the list structure. This results in faster rendering and better overall performance, particularly in scenarios involving frequent updates or reordering of list items.</p>
</li>
<li><p><strong>Facilitating Component Identification</strong>: Key tags serve as a means of uniquely identifying components within a list, aiding in debugging and component inspection. Placing keys at the top level of mapped elements ensures unambiguous identification of individual components.</p>
</li>
</ol>
<h3 id="heading-avoiding-key-tags-in-paragraph-or-div-elements">Avoiding Key Tags in Paragraph or Div Elements</h3>
<p>While it may be tempting to assign keys to paragraph or div elements within list items, doing so can lead to unintended consequences. Placing keys at this level may cause React to overlook structural changes within the list, potentially resulting in rendering errors or inconsistencies.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>In conclusion, the strategic use of key tags during list mapping is paramount for optimizing performance and maintaining code integrity in React applications. By assigning keys directly within the <code>map()</code> function and avoiding placement within paragraph or div tags, developers can ensure efficient list rendering and facilitate smoother user experiences.</p>
<p>Embrace the power of key tags in list mapping, and unlock the full potential of React's rendering optimizations in your projects!</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Unlocking Web Design Potential]]></title><description><![CDATA[In the world of web development, CSS (Cascading Style Sheets) plays a crucial role in determining the visual presentation of a webpage. While many developers are familiar with basic CSS selectors like class and ID selectors, mastering more advanced s...]]></description><link>https://blog.varunjoshi.co.in/unlocking-web-design-potential</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/unlocking-web-design-potential</guid><category><![CDATA[CSS]]></category><category><![CDATA[css selectors]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Tue, 27 Feb 2024 18:30:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/J5yoGZLdpSI/upload/10d14b0dc6eb2f7cf5a0ffc11ad5fe7c.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the world of web development, CSS (Cascading Style Sheets) plays a crucial role in determining the visual presentation of a webpage. While many developers are familiar with basic CSS selectors like class and ID selectors, mastering more advanced selectors can significantly enhance your ability to style web pages with precision and efficiency.</p>
<p>In this article, we'll explore some lesser-known CSS selectors that can be incredibly powerful when used correctly. By understanding and implementing these selectors effectively, you can take your web design skills to the next level. Just a pro tip, this was asked in the Interview.</p>
<ol>
<li><p>Descendant Selector (<code>div p</code>): The descendant selector targets all <code>&lt;p&gt;</code> elements that are descendants of a <code>&lt;div&gt;</code> element. This allows you to style paragraphs specifically within a particular section or container, without affecting other paragraphs on the page.</p>
</li>
<li><p>Child Selector (<code>div &gt; p</code>): The child selector targets only the <code>&lt;p&gt;</code> elements that are direct children of a <code>&lt;div&gt;</code> element. This selector provides even greater specificity, ensuring that only paragraphs immediately nested within the specified <code>&lt;div&gt;</code> are styled accordingly.</p>
</li>
<li><p>Adjacent Sibling Selector (<code>div + p</code>): The adjacent sibling selector targets the <code>&lt;p&gt;</code> element that directly follows a <code>&lt;div&gt;</code> element. This can be useful for applying unique styles to paragraphs that immediately follow specific elements, such as headers or dividers.</p>
</li>
<li><p>General Sibling Selector (<code>div ~ p</code>): The general sibling selector targets all <code>&lt;p&gt;</code> elements that are siblings of a <code>&lt;div&gt;</code> element. This allows you to apply consistent styles to paragraphs that share the same parent element.</p>
</li>
</ol>
<pre><code class="lang-css"><span class="hljs-comment">/* Selects all &lt;p&gt; elements that are descendants of a &lt;div&gt; element */</span>
<span class="hljs-selector-tag">div</span> <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">color</span>: blue; 
  }

  <span class="hljs-comment">/* Selects all &lt;p&gt; elements that are direct children of a &lt;div&gt; element */</span>
  <span class="hljs-selector-tag">div</span> &gt; <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">color</span>: red; 
  }

  <span class="hljs-comment">/* Selects the &lt;p&gt; element that is immediately preceded by a &lt;div&gt; element */</span>
  <span class="hljs-selector-tag">div</span> + <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">color</span>: green; <span class="hljs-comment">/* Example color */</span>
  }

  <span class="hljs-comment">/* Selects all &lt;p&gt; elements that are siblings of a &lt;div&gt; element */</span>
  <span class="hljs-selector-tag">div</span> ~ <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">color</span>: orange;
  }
</code></pre>
<p>Wondering what is the prirority for this ?  </p>
<ol>
<li><p>Inline styles: Styles defined directly within the HTML element using the <code>style</code> attribute. Inline styles have the highest specificity and will override any other styles applied externally.</p>
</li>
<li><p>ID selectors: Selectors targeting elements by their unique <code>id</code> attribute. They have a higher specificity compared to class selectors.</p>
</li>
<li><p>Class selectors, attribute selectors, and pseudo-classes: Selectors targeting elements based on their class names, attributes, or pseudo-classes (like <code>:hover</code>, <code>:focus</code>, etc.).</p>
</li>
<li><p>Element selectors and pseudo-elements: Selectors targeting HTML elements directly, such as <code>div</code>, <code>p</code>, <code>a</code>, etc., or pseudo-elements like <code>::before</code> and <code>::after</code>.</p>
</li>
<li><p>Universal selectors and combinators: Selectors that apply styles universally or based on relationships between elements, such as <code>*</code>, <code>+</code>, <code>&gt;</code>, <code>~</code>, etc.</p>
</li>
</ol>
<p>By incorporating these advanced CSS selectors into your coding repertoire, you can achieve finer control over the styling of your web pages. Whether you're refining the layout of a complex website or adding subtle design touches to enhance user experience, mastering these selectors is sure to elevate your CSS skills.  </p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/coding-bee/pen/LYvpgWa">https://codepen.io/coding-bee/pen/LYvpgWa</a></div>
<p> </p>
<p>Experiment with these selectors in your projects to gain a deeper understanding of their capabilities and nuances. With practice and creativity, you'll soon find yourself wielding CSS selectors like a true master, effortlessly crafting visually stunning web pages with precision and flair.</p>
<p>So, dive into the world of CSS selectors and unlock a new level of styling finesse for your web development endeavors.</p>
]]></content:encoded></item><item><title><![CDATA[HTML Unveiled: Mastering Essential Tags 😮]]></title><description><![CDATA[HTML tags or elements are made to wrap, mark or enclose to make them act in a certain way, but it doesn't mean that you use them to avoid the CSS part. Well everyone has their best practices defined but there is nothing more specific until you know w...]]></description><link>https://blog.varunjoshi.co.in/html-unveiled-mastering-essential-tags</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/html-unveiled-mastering-essential-tags</guid><category><![CDATA[HTML]]></category><category><![CDATA[HTML tags ]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[webdev]]></category><category><![CDATA[HTML5]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Sat, 10 Feb 2024 18:08:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/OqtafYT5kTw/upload/bd0c28699d6f9a1739bd7aeb8a5e0a30.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>HTML tags or elements are made to wrap, mark or enclose to make them act in a certain way, but it doesn't mean that you use them to avoid the CSS part. Well everyone has their best practices defined but there is nothing more specific until you know what you're trying to do.</p>
<p>let's jump to the code(I know most of you don't consider it to be the code) to directly learn different behaviors and the emphasis on using those tags and learning to use them correctly.</p>
<ul>
<li>&lt;pre&gt; Element</li>
</ul>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span> Dreams - By Langston Hughes<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">pre</span>&gt;</span>
        Hold fast to dreams <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
        For if dreams die <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
        Life is a broken-winged bird <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
        That cannot fly. <span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">pre</span>&gt;</span>
</code></pre>
<ul>
<li><p>Pre will be rendered with a monospaced font and with all of your extra white space intact.</p>
</li>
<li><p>It gives an extra indent to highlight the context.</p>
</li>
<li><p>Useful when you want to showcase a block of code.</p>
</li>
<li><p>Formatted Strings</p>
</li>
</ul>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>
    formatting
  <span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">strong</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">strong</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">em</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">small</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">small</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">sub</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">sub</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">super</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">super</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">ins</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">ins</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">del</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">del</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>I am looking to <span class="hljs-tag">&lt;<span class="hljs-name">mark</span>&gt;</span>hire<span class="hljs-tag">&lt;/<span class="hljs-name">mark</span>&gt;</span> a team for dev work. <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<ul>
<li><p><code>&lt;Strong&gt;</code> would bring emphasis to a particular word or sentence by making it bolder or increasing its font-weight</p>
</li>
<li><p><code>&lt;em&gt;</code> would emphasize the word enclosed in the tag</p>
</li>
<li><p><code>&lt;small&gt;</code> tag would reduce the font size of the given enclosed in the tag</p>
</li>
<li><p>superscript and subscript can be achieved by the tags <code>super</code> and <code>sub</code></p>
</li>
<li><p><code>ins</code> would underline the word enclosed and <code>del</code> will <s>strike </s> line</p>
</li>
<li><p><code>mark</code> is an interesting tag to <mark>highlight</mark> the keyword, just like highlighting a word in a line with the yellow marker</p>
</li>
</ul>
<p>That's all for this topic, Let me know which is your favorite tag 🤗</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/coding-bee/pen/vYaaYRq">https://codepen.io/coding-bee/pen/vYaaYRq</a></div>
]]></content:encoded></item><item><title><![CDATA[Water Tank Problem]]></title><description><![CDATA[Redbus conducts its First round on Hackerath platform, the exam goes for around 1.30 hours and the pattern keeps changing 

23 - aptitude,technical MCQ questions 
AND 3 Coding questions (Medium to Hard)

Water tank problem and the question is here 

...]]></description><link>https://blog.varunjoshi.co.in/water-tank-problem</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/water-tank-problem</guid><category><![CDATA[Python]]></category><category><![CDATA[interview]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Tue, 07 Sep 2021 08:51:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1631004517501/yjrMnZqw2.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Redbus conducts its First round on Hackerath platform, the exam goes for around 1.30 hours and the pattern keeps changing </p>
<blockquote>
<p><strong>23</strong> - aptitude,technical MCQ questions 
AND <strong>3</strong> Coding questions (Medium to Hard)</p>
</blockquote>
<p>Water tank problem and the question is here </p>
<blockquote>
<p>You have exactly N water tankers. Each of the tanker has a capacity of Ci, and contains Wi, amount of water. You can transfer any amount of water from one tanker to another, any number of times. The total amount of water is the sum of the amount of water in all the tankers. You have to transport the total amount of water to another city You need to find the <strong>minimum number</strong> of tankers required to transport the total amount of water</p>
</blockquote>
<h5 id="example">Example</h5>
<p>Consider N-2
C-[2,2] W-[1 ,1] You must determine the minimum number of tankers required:
We can transfer water of tank 1 to tank 2. So, we required only 1 tanker.</p>
<p>Function description
returns the count of c</p>
<p>N:Represents the number of tankers.
C: An array of size N, represents the Capacity in the tankers</p>
<p>W: An array of size N, represents the current water in the tankers</p>
<p>Here is my approach</p>
<pre><code>n = int(input())
<span class="hljs-built_in">count</span> = <span class="hljs-number">0</span>
total_remaining = []
<span class="hljs-built_in">c</span> = [int(y) <span class="hljs-keyword">for</span> y <span class="hljs-keyword">in</span> input(<span class="hljs-string">"Enter multiple values\n"</span>).<span class="hljs-built_in">split</span>()] [:n]
w = [int(x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> input(<span class="hljs-string">"Enter multiple values\n"</span>).<span class="hljs-built_in">split</span>()] [:n]
<span class="hljs-built_in">print</span>(<span class="hljs-string">"Water tanks are:"</span>,w)
<span class="hljs-built_in">print</span>(<span class="hljs-string">"Capacity is:"</span>,<span class="hljs-built_in">c</span>)


total_capacity = sum(<span class="hljs-built_in">c</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">"total_capacity:"</span>,total_capacity)

total_water = sum(w)
<span class="hljs-built_in">print</span>(<span class="hljs-string">"total water:"</span>,total_water)


total_remaining= [<span class="hljs-built_in">c</span>[i]-w[i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-built_in">min</span>(len(w), len(<span class="hljs-built_in">c</span>)))]
<span class="hljs-built_in">print</span>(total_remaining)

<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(len(total_remaining)):
  <span class="hljs-keyword">if</span> total_water&gt;<span class="hljs-number">0</span>: 
    <span class="hljs-built_in">count</span>+= <span class="hljs-number">1</span>
    total_water -= total_remaining[i]
    <span class="hljs-built_in">print</span>(<span class="hljs-string">"remaing water is:"</span>,total_water)    
<span class="hljs-built_in">print</span>(<span class="hljs-string">"The water tanker required is:"</span>,<span class="hljs-built_in">count</span>-<span class="hljs-number">1</span>)
</code></pre><p>Comment a better Version here !</p>
]]></content:encoded></item><item><title><![CDATA[Introduction to Arrays]]></title><description><![CDATA[What is an array?
An Array is a collection of the elements of Similar Data-Type stored one after another in the memory.
why do we use array ?

We can overcome the disadvantage of using many variables since variables are used to store more than one el...]]></description><link>https://blog.varunjoshi.co.in/introduction-to-arrays</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/introduction-to-arrays</guid><category><![CDATA[array]]></category><category><![CDATA[C]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Sun, 15 Aug 2021 05:12:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1626246283665/v6OFBO1kK.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="what-is-an-array">What is an array?</h3>
<p>An Array is a collection of the elements of Similar Data-Type stored one after another in the memory.</p>
<h3 id="why-do-we-use-array">why do we use array ?</h3>
<ul>
<li>We can overcome the disadvantage of using many variables since variables are used to store more than one element of the same datatype.</li>
</ul>
<p>Types of arrays.</p>
<ul>
<li>1D Array</li>
<li>2D Array</li>
<li>3D Array</li>
</ul>
<p>Syntax to declare</p>
<pre><code><span class="hljs-selector-tag">Datatypes</span> <span class="hljs-selector-tag">array_name</span><span class="hljs-selector-attr">[expression]</span>;
</code></pre><h3 id="quick-note">Quick Note.</h3>
<blockquote>
<p>ArraySize = No of elements * size of datatype</p>
<p>Array indexing starts from 0</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1626246523389/4uYM5mTp0.png" alt="A[3] (2).png" /></p>
<h3 id="different-ways-of-array-initialization">Different ways of array Initialization</h3>
<ul>
<li><ol>
<li><strong>Initializing all the memory location</strong></li>
</ol>
</li>
</ul>
<p>No of elements = Number of Elements</p>
<pre><code><span class="hljs-attribute">Int</span> a[<span class="hljs-number">5</span>] = { <span class="hljs-number">10</span>,<span class="hljs-number">20</span>,<span class="hljs-number">30</span>,<span class="hljs-number">40</span>,<span class="hljs-number">50</span>}
</code></pre><ul>
<li><ol>
<li><strong>Partial Array Initialization</strong> <br />
If the number of values initialized is less than the allocated memory then it is known as partial array initialization.</li>
</ol>
</li>
</ul>
<pre><code><span class="hljs-attribute">Int</span> a[<span class="hljs-number">5</span>] = { <span class="hljs-number">10</span>,<span class="hljs-number">20</span>,<span class="hljs-number">30</span>,<span class="hljs-number">40</span>,<span class="hljs-number">70</span>}
</code></pre><ul>
<li><ol>
<li><strong>Initialization without size</strong> </li>
</ol>
</li>
</ul>
<p>The number of elements has not been specified to values specified.</p>
<pre><code><span class="hljs-string">int</span> <span class="hljs-string">a</span> [ ] <span class="hljs-string">=</span> {<span class="hljs-number">10</span>,<span class="hljs-number">20</span>,<span class="hljs-number">30</span>}<span class="hljs-string">;</span>
</code></pre><ul>
<li><ol>
<li><strong>String Initialization </strong>
Strings are defined as an array of characters with a null character in the end.</li>
</ol>
</li>
</ul>
<pre><code><span class="hljs-built_in">char</span> <span class="hljs-built_in">str</span>[<span class="hljs-number">50</span>] = <span class="hljs-string">"GeeksforGeeks"</span>;
</code></pre><h3 id="program-to-read-array-and-print-it">Program to Read Array and print it.</h3>
<pre><code><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span><span class="hljs-meta-string">&lt;stdio.h&gt;</span></span>


<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span>
</span>{
<span class="hljs-keyword">int</span> i,arr[<span class="hljs-number">10</span>], range;

<span class="hljs-built_in">printf</span>(<span class="hljs-string">"Enter the number of elements in array:\n"</span>);
<span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%d"</span>, &amp;range);

<span class="hljs-built_in">printf</span>(<span class="hljs-string">"Enter the array elements:\n"</span>);
    <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>; i&lt;range; i++)
    {
    <span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%d"</span>, &amp;arr[i]);
    }

<span class="hljs-built_in">printf</span>(<span class="hljs-string">"aray elements are as follows:"</span>);
    <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>; i&lt;range; i++)
    {
    <span class="hljs-built_in">printf</span>(<span class="hljs-string">"%d "</span>, arr[i]);
    }

}
</code></pre>]]></content:encoded></item><item><title><![CDATA[Non-Repeated Characters in String]]></title><description><![CDATA[Here is a problem I recently came with an interview. Let's see the way we can solve this using python
Problem

A data Compression software utilizes various steps to compress a string of data. One of the steps involves finding the count of characters ...]]></description><link>https://blog.varunjoshi.co.in/non-repeated-characters-in-string</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/non-repeated-characters-in-string</guid><category><![CDATA[Python 3]]></category><category><![CDATA[interview]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Sat, 31 Jul 2021 11:54:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1627732299945/iyio1jMD9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here is a problem I recently came with an interview. Let's see the way we can solve this using python</p>
<h3 id="problem">Problem</h3>
<blockquote>
<p>A data Compression software utilizes various steps to compress a string of data. One of the steps involves finding the count of characters that are not repeated in the string.
Write an algorithm for the software developer to find the count of characters that are not repeated in the string.</p>
</blockquote>
<p>Input :
The Input consists of a string </p>
<p>Output :
Print the non-repeated characters and the count of characters that are not repeated.
if no characters are found print 0</p>
<h3 id="my-approach">My approach :</h3>
<div class="gist-block embed-wrapper" data-gist-show-loading="false" data-id="ba8f47a6e66a52ecb385b8f9d60e72ee"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a href="https://gist.github.com/sixthcodebrewer/ba8f47a6e66a52ecb385b8f9d60e72ee" class="embed-card">https://gist.github.com/sixthcodebrewer/ba8f47a6e66a52ecb385b8f9d60e72ee</a></div><p>If you have a better way to solve this problem, do comment down below. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1627732316741/dYccytK85.png" alt="3a854213c52fdcfe4643cf0c6d956c74.png" /></p>
]]></content:encoded></item><item><title><![CDATA[DNS Config for Github Custom Domain]]></title><description><![CDATA[Recently I just published my portfolio at no cost, more about that in the next blog. I had troubleshot with configuring the Custom Domain on GitHub, here I am going to discuss how easy it is to config your Custom Domain on GitHub.
Before we jump to D...]]></description><link>https://blog.varunjoshi.co.in/dns-config-for-github-custom-domain</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/dns-config-for-github-custom-domain</guid><category><![CDATA[dns]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Web Hosting]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Sat, 01 May 2021 01:59:28 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1619854989017/h6rgZf63C.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Recently I just published my <a target="_blank" href="https://joshivarun.tech">portfolio</a> at no cost, more about that in the next blog. I had troubleshot with configuring the Custom Domain on GitHub, here I am going to discuss how easy it is to config your Custom Domain on GitHub.</p>
<p>Before we jump to DNS configuration, let me walk through the setup that is required.
Here are the following things I used for my setup.</p>
<ul>
<li><a target="_blank" href="https://pages.github.com/">GitHub Pages for code hosting</a></li>
<li><a target="_blank" href="https://get.tech/">.Tech Domain</a> with a free ssl certificate</li>
</ul>
<p>you could use any other domain providers like Namecheap, Name.com, GoDaddy, etc.</p>
<h3 id="part-a">Part A</h3>
<h4 id="dns-configuration">DNS Configuration</h4>
<p>DNS stands for Domain Name System. Since we cannot remember the IP address of the websites hosted we use the domain name, which is mapped to these IP addresses. </p>
<blockquote>
<p><a target="_blank" href>www.hosteddomain.com</a></p>
<ul>
<li>where www : is a label</li>
<li>hosteddomain: second-level domain</li>
<li>com: a top-level domain.</li>
</ul>
</blockquote>
<h4 id="lets-us-see-how-we-can-config-now">Lets us see how we can config now</h4>
<ul>
<li>login to your domain provider dashboard, this is how it appears for .tech domains.</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1619844984647/ulSQanoG-.png" alt="Screenshot (147).png" /></p>
<ul>
<li>click on Manage DNS </li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1619845047844/_tyqEFvWU.png" alt="Screenshot (144).png" /></p>
<ul>
<li>you will be redirected to another window with such an interface. we can see that there are lot of different ways to setup a dns </li>
</ul>
<h3 id="there-are-two-ways-to-configure-the-dns-for-github-custom-domain">There are two ways to configure the dns for GitHub custom domain.</h3>
<h4 id="1-a-records">1. A Records</h4>
<p>A-records point to a specific IP address. Subdomains sometimes have A-records too. An A-record can point to any IP address.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1619845296828/XMKo8Eg80.jpeg" alt="Screenshot (142)_LI.jpg" /></p>
<ul>
<li>click on add record</li>
<li>add value as @</li>
<li><p>in the value provide the IP address provided by GitHub. You will need to add all these IP addresses by creating 4 different records.</p>
<pre><code>185<span class="hljs-selector-class">.199</span><span class="hljs-selector-class">.108</span><span class="hljs-selector-class">.153</span>
185<span class="hljs-selector-class">.199</span><span class="hljs-selector-class">.109</span><span class="hljs-selector-class">.153</span>
185<span class="hljs-selector-class">.199</span><span class="hljs-selector-class">.110</span><span class="hljs-selector-class">.153</span>
185<span class="hljs-selector-class">.199</span><span class="hljs-selector-class">.111</span><span class="hljs-selector-class">.153</span>
</code></pre><p>these are the IP addresses provided by the GitHub.</p>
</li>
<li><p>add ttl value</p>
</li>
<li><p><strong>what is ttl value</strong> ?</p>
</li>
</ul>
<p>Time To Live is the sort of expiration date that is put on a DNS record. The TTL serves to tell the recursive server or local resolver how long it should keep said record in its cache.
You can get the TTL value by pinging an address.</p>
<blockquote>
<p>you can provide any value above 7200s for your sites.</p>
</blockquote>
<pre><code><span class="hljs-selector-tag">ping</span> <span class="hljs-selector-tag">www</span><span class="hljs-selector-class">.example</span><span class="hljs-selector-class">.com</span>
</code></pre><p>here is how example how it looks.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1619841437005/VYzGFX0L_.png" alt="blog.PNG" /></p>
<h4 id="2-c-name">2. C Name</h4>
<p> CNAME-Records (Canonical Domain Records) – CNAMEs should always point to an A-record, not another. It is one of the easy ways to config your dns.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1619845517497/Cmdzay0kt.jpeg" alt="Screenshot (144)_LI.jpg" /></p>
<ul>
<li><p>leave the host link blank</p>
</li>
<li><p>select the value ,second radio button to point to your GitHub account</p>
</li>
</ul>
<pre><code><span class="hljs-selector-tag">yourusername</span><span class="hljs-selector-class">.github</span><span class="hljs-selector-class">.io</span>.
</code></pre><ul>
<li>add ttl value anything in mins. </li>
</ul>
<p>If you are using CNAME or ALIAS records for your custom domain, you’re all set and your site should be accessible over HTTPS. If it is, and your site loads correctly over HTTPS, you can optionally enforce HTTPS in your repository’s settings. Users who request your site over HTTP will be upgraded to HTTPS.</p>
<h3 id="check-if-your-dns-is-configured">check if your DNS is configured</h3>
<pre><code><span class="hljs-selector-tag">dig</span> <span class="hljs-selector-tag">www</span><span class="hljs-selector-class">.example</span><span class="hljs-selector-class">.com</span>

&gt; <span class="hljs-selector-tag">WWW</span><span class="hljs-selector-class">.EXAMPLE</span><span class="hljs-selector-class">.COM</span>.                 <span class="hljs-selector-tag">IN</span>      <span class="hljs-selector-tag">A</span>
&gt; <span class="hljs-selector-tag">WWW</span><span class="hljs-selector-class">.EXAMPLE</span><span class="hljs-selector-class">.COM</span>          39812 <span class="hljs-selector-tag">IN</span>   <span class="hljs-selector-tag">CNAME</span>   <span class="hljs-selector-tag">YOUR-USERNAME</span><span class="hljs-selector-class">.github</span><span class="hljs-selector-class">.io</span>.
&gt; <span class="hljs-selector-tag">YOUR-USERNAME</span><span class="hljs-selector-class">.github</span><span class="hljs-selector-class">.io</span>. 43192 <span class="hljs-selector-tag">IN</span>      <span class="hljs-selector-tag">CNAME</span>    <span class="hljs-selector-tag">GITHUB-PAGES-SERVER</span> .
</code></pre><h3 id="part-b">Part B</h3>
<h4 id="github-setup">GitHub Setup</h4>
<ol>
<li><p>Go to your GitHub Repository settings.</p>
</li>
<li><p>Click on Pages. </p>
</li>
<li><p>Add your Custom Domain.</p>
<ul>
<li>Click on Save</li>
<li>wait for GitHub to do Magic!</li>
<li>if you face any error we will troubleshoot in end of the section.</li>
</ul>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1619845551941/js3H0kfkZ.png" alt="Screenshot (149).png" /></p>
<ul>
<li>GitHub will push CNAME file pointing to your domain name,If not you can create CNAME file.</li>
<li>add your domain name </li>
<li>commit the file 
If you use a static site generator to build your site locally and push the generated files to GitHub, pull the commit that added the CNAME file to your local repository. </li>
</ul>
<h4 id="troubleshot-errors">Troubleshot errors</h4>
<p>1.DNS misconfiguration</p>
<p>2.InvalidDNSError
www.example.tech is improperly configured
Domain's DNS record could not be retrieved. For more information, see Learn more (InvalidDNSError). We recommend you change this to a CNAME record pointing to username.github.io.</p>
<h4 id="how-to-troubleshot">How to troubleshot</h4>
<ul>
<li><p>Check your CNAME FILENAME.(it should be in uppercase)</p>
</li>
<li><p>Check if your GitHub Setup is configured properly.</p>
</li>
<li><p>Confirm your settings </p>
</li>
<li><p>Domain Propagation Delay Occurs so wait for 24 to 48 hours to let your website to be live.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Demystifying Markdown for GitHub]]></title><description><![CDATA[All of us have wondered how to write the Readme.md file while understanding the GitHub workflows, how does the documentation work, and how to write a wiki for the project. The Answer is MarkDown

MarkDown language helps up in documenting the project ...]]></description><link>https://blog.varunjoshi.co.in/demystifying-markdown</link><guid isPermaLink="true">https://blog.varunjoshi.co.in/demystifying-markdown</guid><category><![CDATA[markdown]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><dc:creator><![CDATA[Varun Joshi]]></dc:creator><pubDate>Thu, 04 Mar 2021 04:17:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1614830259627/mC88vTPI5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>All of us have wondered how to write the Readme.<strong>md</strong> file while understanding the GitHub workflows, how does the documentation work, and how to write a wiki for the project. The Answer is <strong>MarkDown</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614825106088/8IWRGDrGx.webp" alt="markdown-512.webp" />
MarkDown language helps up in documenting the project in a better way, it is simply the lightweight markup language that helps in converting the text into markup language(html) which is easier to read.
Lets us understand how to write this markdown language.</p>
<p></p>
<h4 id="1-heading">1. Heading</h4>
<p>markdown supports different sizes of headings, which helps differentiate between the heading, title, and subtitle.</p>
<pre><code><span class="hljs-comment"># I am highest size heading ( &lt;h1&gt; tag )</span>
<span class="hljs-comment">## I am a little smaller than the first ( &lt;h2&gt; tag )</span>
<span class="hljs-comment">### I am smaller than the second size ( &lt;h3&gt; tag )</span>
<span class="hljs-comment">#### I am smaller than the third size  ( &lt;h4&gt; tag )</span>
<span class="hljs-comment">##### I am smaller than the fourth size ( &lt;h5&gt; tag )</span>
<span class="hljs-comment">###### I am the smallest size of the heading. ( &lt;h6&gt; tag )</span>
</code></pre><p>This is how it looks.</p>
<h1 id="i-am-highest-size-heading">I am highest size heading</h1>
<h2 id="i-am-a-little-smaller-than-the-first">I am a little smaller than the first</h2>
<h3 id="i-am-smaller-than-the-second-size">I am smaller than the second size</h3>
<h4 id="i-am-smaller-than-the-third-size">I am smaller than the third size</h4>
<h5 id="i-am-smaller-than-the-fourth-size">I am smaller than the fourth size</h5>
<h6 id="i-am-the-smallest-size-of-the-heading">I am the smallest size of the heading.</h6>
<h4 id="2-linking-images">2. Linking Images</h4>
<p>can be Linked following way using CDN link</p>
<pre><code>!(alt-<span class="hljs-type">name</span> <span class="hljs-keyword">of</span> image)[<span class="hljs-type">path</span> <span class="hljs-keyword">of</span> the image]
</code></pre><h4 id="3-link">3. Link</h4>
<p>Link Can be used to represent different attachments and third-party software.</p>
<pre><code>[<span class="hljs-string">Text that appears</span>](<span class="hljs-link">Link</span>)
</code></pre><h4 id="4-emphasis-on-the-text">4. Emphasis on the text</h4>
<p>Making text <strong>Bold</strong> by enclosing them between two underscores or two asterisks.</p>
<pre><code>__making <span class="hljs-type">text</span> Bold__
</code></pre><p>or</p>
<pre><code>**making text Bold**
</code></pre><p>The text could be made <strong><em>italics</em></strong> when enclosed between one asterisk or single underscores.</p>
<pre><code>*making <span class="hljs-type">text</span> Italian*
</code></pre><p>or </p>
<pre><code>_making <span class="hljs-type">text</span> Italian_
</code></pre><pre><code>_*Bold and italian*_
</code></pre><h4 id="5-ordered-list">5. Ordered List</h4>
<p>ordered List used to represent different items like the stack, contributor guidelines, guide to starting the project which can be done following way.</p>
<pre><code><span class="hljs-bullet">1.</span> first Item
<span class="hljs-bullet">2.</span> Second Item 
<span class="hljs-bullet">3.</span> Third Item
</code></pre><h4 id="6-unordered-list">6. Unordered List</h4>
<p>unordered List used to represent different items which can be done following way.</p>
<pre><code><span class="hljs-bullet">*</span> Item
<span class="hljs-bullet">*</span> Item 
<span class="hljs-bullet">*</span> Item
</code></pre><h4 id="7-quote">7. Quote</h4>
<pre><code>&gt; <span class="hljs-keyword">using</span> greater than a symbol <span class="hljs-keyword">to</span> <span class="hljs-keyword">Quote</span> a <span class="hljs-keyword">statement</span>.
</code></pre><p>These were some of the basic syntax that can be used everywhere. But to make it easy but github provides additional feature like </p>
<h4 id="task-list">Task List</h4>
<p>Tasklist helps to merge a pull-request submitted, which defines all the new feature added or changes done to source code.</p>
<pre><code><span class="hljs-selector-tag">-</span><span class="hljs-selector-attr">[X]</span> <span class="hljs-selector-tag">task</span> <span class="hljs-selector-tag">1</span>
<span class="hljs-selector-tag">-</span><span class="hljs-selector-attr">[]</span> <span class="hljs-selector-tag">Not</span> <span class="hljs-selector-tag">completed</span> <span class="hljs-selector-tag">task</span>
</code></pre><h4 id="emoji">Emoji</h4>
<p>Github Supports different emojis to make the documentation attractive.</p>
<pre><code>Emojis supported <span class="hljs-keyword">on</span> Github are predefined <span class="hljs-keyword">and</span> enclosed <span class="hljs-keyword">between</span> colon
:<span class="hljs-type">name</span>:
:+<span class="hljs-number">1</span>:
</code></pre><p>you can find all the name of the emojis <a target="_blank" href="https://github.com/ikatyang/emoji-cheat-sheet/blob/master/README.md">here</a></p>
<h3 id="markdown-preview-in-vscode">markdown preview in vscode.</h3>
<p>If you use vscode then you can install this extension  <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced">Markdown Preview Enhanced</a> written by Yiyi Wang which will make it easier for documentation.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1614827663637/jLTCI0aXo.png" alt="Screenshot from 2021-03-04 08-40-43.png" /></p>
]]></content:encoded></item></channel></rss>