<?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: Bukunmi Odugbesan</title>
    <description>The latest articles on DEV Community by Bukunmi Odugbesan (@tomivan).</description>
    <link>https://dev.to/tomivan</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%2F182757%2Fef9b7f5f-efdd-416a-9ec3-69246cb9b821.jpeg</url>
      <title>DEV Community: Bukunmi Odugbesan</title>
      <link>https://dev.to/tomivan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tomivan"/>
    <language>en</language>
    <item>
      <title>Coding Challenge Practice - Question 120</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Tue, 17 Feb 2026 21:35:40 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-120-2bmh</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-120-2bmh</guid>
      <description>&lt;p&gt;The task is to write a function to remove duplicate characters in a string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function smallestUniqueSubstr(str) {
  // your code here
}

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

&lt;/div&gt;



&lt;p&gt;Count the remaining occurrences of each character. This stores how many times each character appears&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const remaining = {};
for(const ch of str) {
remaining[ch] = (remaining[ch] || 0) + 1;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create data structures to build the final result and ensure uniqueness&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const stack = []
const inStack = new Set()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Iterate through the string. Decrease the count as the character is being processed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(const ch of str) {
remaining[ch]--
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Skip the character if it has already been added to the result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(inStack.has(ch)) return;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove characters from the stack if the stack is not empty, the current character is smaller top character, and the top character is greater than zero&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while(
  stack.length &amp;gt; 0 &amp;amp;&amp;amp;
  stack[stack.length - 1] &amp;gt; ch &amp;amp;&amp;amp;
  remaining[stack[stack.length -1]] &amp;gt; 0
) {
  inStack.delete(stack.pop());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the current character to the result if all conditions are not met&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stack.push(ch);
inStack.add(ch);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return the final result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return stack.join('')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final solution&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function smallestUniqueSubstr(str) {
  // your code here
  const remaining = {};
  for(const ch of str) {
    remaining[ch] = (remaining[ch] || 0) + 1
  }

  const inStack = new Set();
  const stack = [];

  for(const ch of str) {
    remaining[ch]--;

    if(inStack.has(ch)) continue;

    while(stack.length &amp;gt; 0 &amp;amp;&amp;amp; stack[stack.length - 1] &amp;gt; ch &amp;amp;&amp;amp; 
    remaining[stack[stack.length -1]] &amp;gt; 0) {
      inStack.delete(stack.pop());
    }
    stack.push(ch);
    inStack.add(ch);
  }
  return stack.join('')
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>computerscience</category>
      <category>devchallenge</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 119</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Thu, 12 Feb 2026 22:34:51 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-119-32d8</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-119-32d8</guid>
      <description>&lt;p&gt;The task is to implement a function that validates IPv4 and IPv6 IP addresses.&lt;/p&gt;

&lt;p&gt;The boilerplate 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 isValidIP(str) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A valid IPv4 address should be in 4 parts, separated by ".", and should contain digits between 0 and 255, with no number having a leading zero. Create a function to validate those parameters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isValidIPv4(ip) {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part should be separated by "."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const parts = ip.split(".");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There must be exactly 4 parts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(parts.length !== 4) return false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the number is less than zero or greater than 255, it is not a valid IPv4 address. The number should also not have a leading 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (const part of parts) {
    if (!/^\d+$/.test(part)) return false;
    if (part.length &amp;gt; 1 &amp;amp;&amp;amp; part[0] === '0') return false;

    const num = Number(part);
    if (num &amp;lt; 0 || num &amp;gt; 255) return false;
  }
  return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The complete function to validate an IPv4 address&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isValidIPv4(ip) {
  const parts = ip.split('.');
  if (parts.length !== 4) return false;

  for (const part of parts) {
    if (!/^\d+$/.test(part)) return false;
    if (part.length &amp;gt; 1 &amp;amp;&amp;amp; part[0] === '0') return false;

    const num = Number(part);
    if (num &amp;lt; 0 || num &amp;gt; 255) return false;
  }
  return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A valid IPv6 address is exactly 8 parts, separated by ":". Each part contains 1 to 4 characters in hex digits. Create a function to validate these parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isValidIPv6(ip) {
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part must be separated by ":"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const parts = ip.split(":");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There must be exactly 8 parts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(parts.length !== 8) return false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the part has fewer than 1 or more than 4 characters, it is invalid. The characters should also follow the hex code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (const part of parts) {
    if (part.length &amp;lt; 1 || part.length &amp;gt; 4) return false;
    if (!/^[0-9a-fA-F]+$/.test(part)) return false;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The complete function to validate an IPv6 address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isValidIPv6(ip) {
  const parts = ip.split(':');
  if (parts.length !== 8) return false;

  for (const part of parts) {
    if (part.length &amp;lt; 1 || part.length &amp;gt; 4) return false;
    if (!/^[0-9a-fA-F]+$/.test(part)) return false;
  }
  return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The address could either be an IPv4 or IPv6 address. If it is an IPv4 address, it would contain "."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(str.includes('.')) {
    return isValidIPv4(str) ? true : false;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it is an IPv6 address, it would contain ":"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(str.includes(':')) {
    return isValidIPv6(str) ? true : false;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"." and ":" are the first differentiators, before the address are further validated with either function. The final 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 isValidIP(str) {
  // your code here
  if(str.includes('.')) {
    return isValidIPv4(str) ? true : false;
  }

  if(str.includes(':')) {
    return isValidIPv6(str) ? true : false;
  }
  return false;
}

function isValidIPv4(ip) {
  const parts = ip.split('.');
  if(parts.length !== 4) return false;

  for(const part of parts) {
    if(!/^\d+$/.test(part)) return false;
    if(part.length &amp;gt; 1 &amp;amp;&amp;amp; part[0] === '0') return false;

    const num = Number(part);
    if(num &amp;lt; 0 || num &amp;gt; 255) return false;
  }
  return true;
}

function isValidIPv6(ip) {
  const parts = ip.split(':');
  if(parts.length !== 8) return false;

  for(const part of parts) {
    if(part.length &amp;lt; 1 || part.length &amp;gt; 4) return false;
    if(!/^[0-9a-fA-F]+$/.test(part)) return false;
  }
  return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>coding</category>
      <category>javascript</category>
      <category>networking</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 118</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Tue, 10 Feb 2026 22:34:27 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-118-1joj</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-118-1joj</guid>
      <description>&lt;p&gt;The task is to implement a function to add class names.&lt;/p&gt;

&lt;p&gt;The boilerplate 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 classNames(...args) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function should combine different kinds of input into one space-separated string. &lt;/p&gt;

&lt;p&gt;Create a variable to store the result&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const result = []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the argument is not a string, number, array, or object, skip it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const process = (arg) =&amp;gt; {
    if (!arg) return;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the argument is a string or a number, push is immediately&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (typeof arg === 'string' || typeof arg === 'number') {
      result.push(arg);
      return;
    }

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

&lt;/div&gt;



&lt;p&gt;If the argument is an array, loop through it again (recursion)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (Array.isArray(arg)) {
      arg.forEach(process);
      return;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the argument is an object, check each key's value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
    if (typeof arg === 'object') {
      for (const key in arg) {
        if (arg[key]) {
          result.push(key);
        }
      }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 classNames(...args) {
  // your code here
  const result = [];

  const process = (arg) =&amp;gt; {
    if(!arg) return;

    if(typeof arg === 'string' || typeof arg === "number") {
      result.push(arg);
      return;
    }
    if(Array.isArray(arg)) {
      arg.forEach(process);
      return;
    }
    if(typeof arg === 'object') {
      for(const key in arg) {
        if(arg[key]) {
          result.push(key);
        }
      }
    }
  }
  args.forEach(process);

  return result.join(' ');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>coding</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 117</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Mon, 09 Feb 2026 14:25:37 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-117-27on</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-117-27on</guid>
      <description>&lt;p&gt;The task is to implement an enhanced debounce which has an option to invoke right away or after a delay.&lt;/p&gt;

&lt;p&gt;The boilerplate 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 debounce(func, wait, option = {leading: false, trailing: true}) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep track of the delay required and the latest call data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let timer = null;
let lastArgs;
let lastThis;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the function is called, clear any existing timer and start a new one&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return function(...args) {
lastArgs = args;
lastThis = this;

if(timer) clearTimeout(timer);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is no active timer, the function executes immediately on first call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const shouldCallNow = option.leading &amp;amp;&amp;amp; !timer

if(shouldCallNow) {
func.apply(lastThis, lastArgs)
lastArgs = lastThis = null;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is a timer, the function executes after a waiting period expires&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;timer = setTimeout(() =&amp;gt; {
timer = null;
if(option.trailing &amp;amp;&amp;amp; lastArgs) {
func.apply(lastThis, lastArgs)
lastArgs = lastThis = null;
}
}, wait)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 debounce(func, wait, option = {leading: false, trailing: true}) {
  // your code here
  let timer = null;
  let lastArgs;
  let lastThis;

  return function(...args) {
    lastArgs = args;
    lastThis = this;

    const shouldCallNow = option.leading &amp;amp;&amp;amp; !timer;

    if(timer) clearTimeout(timer);

    timer = setTimeout(() =&amp;gt; {
      timer = null;

      if(option.trailing &amp;amp;&amp;amp; lastArgs) {
        func.apply(lastThis, lastArgs)
        lastArgs = lastThis = null;
      }
    }, wait)
    if(shouldCallNow) {
      func.apply(lastThis, lastArgs);
      lastArgs = lastThis = null;
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>coding</category>
      <category>javascript</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 116</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Sat, 07 Feb 2026 17:30:22 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-116-13m0</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-116-13m0</guid>
      <description>&lt;p&gt;The task is to implement Promise.prototype.finally()&lt;/p&gt;

&lt;p&gt;The boilerplate 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 myFinally(promise, onFinally) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Promise.prototype.finally() could be used to return a callback when a promise is settled (fulfilled or rejected).&lt;/p&gt;

&lt;p&gt;Attach &lt;code&gt;.then&lt;/code&gt; to resolve the promise&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return promise.then(
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the promise was fulfilled&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(value) =&amp;gt; {
return Promise.resolve(onFinally &amp;amp;&amp;amp; onFinally()).then(() =&amp;gt; value)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Promise.resolve&lt;/code&gt; is used because it converts normal value to a resolved promise.&lt;/p&gt;

&lt;p&gt;If the promise is rejected&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(error) =&amp;gt; {
return Promise.resolve(onFinally &amp;amp;&amp;amp; onFinally()).then(() =&amp;gt; {
throw error
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 myFinally(promise, onFinally) {
  // your code here
  return promise.then(
    (value) =&amp;gt; {
      return Promise.resolve(onFinally &amp;amp;&amp;amp; onFinally()).then(() =&amp;gt; value);
    },
    (error) =&amp;gt; {
      return Promise.resolve(onFinally &amp;amp;&amp;amp; onFinally()).then(() =&amp;gt; {
        throw error
      })
    }
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>coding</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 115</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Thu, 05 Feb 2026 22:35:08 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-115-2pmn</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-115-2pmn</guid>
      <description>&lt;p&gt;The task is to implement memoizeOne().&lt;/p&gt;

&lt;p&gt;The boilerplate 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 memoizeOne(func, isEqual) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;memoizeOne&lt;/code&gt;is a lightweight memoization function that caches only the most recent function call result.&lt;/p&gt;

&lt;p&gt;Previous arguments, result and context have to be stored. And also need to track if it has been called (subsequent calls should return cached value)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lastArgs = undefined
lastResult = undefined;
lastThis = undefined;
hasBeenCalled = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the first call, mark that the function has been called, store arguments and context, cache and return the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(!hasBeenCalled) {
  hasBeenCalled = true;
  lastArgs = args;
  lastThis = this;
  lastResult = func.apply(this, args);
  return lastResult;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check if the next function call is the same as the previous&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const equalityCheck = isEqual || defaultIsEqual;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, ensure that the context of execution is the same&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(this === lastThis &amp;amp;&amp;amp; equalityCheck(args, lastArgs)) {
  return lastResult;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function to check each function call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function defaultIsEqual(args1, args2) {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the length of both arguments are not equal, the functions are not&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; if(args1.length !== args2.length) {
    return false;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check each argument strictly&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; for(let i = 0; i &amp;lt; args1.length; i++) {
    if(args1[i] !== args2[i]) {
      return false;
    }
  }

  return true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 memoizeOne(func, isEqual) {
  // your code here
  let lastArgs = undefined;
  let lastResult = undefined;
  let hasBeenCalled = false;
  let lastThis = undefined;

  return function (...args) {
    if(!hasBeenCalled) {
      hasBeenCalled = true;
      lastArgs = args; 
      lastThis = this;
      lastResult = func.apply(this, args);
      return lastResult
    }

    const equalityCheck = isEqual || defaultIsEqual;

    if(this ===lastThis &amp;amp;&amp;amp; equalityCheck(args, lastArgs)) {
      return lastResult;
    }

    lastArgs = args;
    lastThis = this;
    lastResult = func.apply(this, args);
    return lastResult;
  }
}

function defaultIsEqual(args1, args2) {
  if(args1.length !== args2.length) {
    return false;
  }

  for(let i = 0; i &amp;lt; args1.length; i++) {
    if(args1[i] !== args2[i]) {
      return false;
    }
  }
  return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>coding</category>
      <category>javascript</category>
      <category>performance</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 114</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Wed, 04 Feb 2026 13:26:28 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-114-p5a</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-114-p5a</guid>
      <description>&lt;p&gt;The task is to find the n-th Fibonacci number.&lt;/p&gt;

&lt;p&gt;The boilerplate 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 fib(n) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fibonacci numbers are the sum of the previous 2 numbers in the Fibonacci sequence. It starts from 0, 1,..., then the addition starts.&lt;/p&gt;

&lt;p&gt;If the n-th Fibonacci number is less than or equal to 1, return the value of n&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(n &amp;lt;= 1) return n;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the variables of the numbers to be added&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let prev = 0;
let curr = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To find the n-th number, keep adding the previous and the current number till n is reached&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(let i = 2; i &amp;lt;= n; i++) {
 const next = prev + curr;
   prev = curr;
   curr = next;
}
return curr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After addition, the current becomes the previous, and the next becomes the current, till n is reached.&lt;/p&gt;

&lt;p&gt;The final 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 fib(n) {
  // your code here
  if(n &amp;lt;= 1) return n;

  let prev = 0;
  let curr = 1;

  for(let i = 2; i &amp;lt;= n; i++) {
    const next = prev + curr;
    prev = curr;
    curr = next;
  }

  return curr;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>computerscience</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 113</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Tue, 03 Feb 2026 15:39:51 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-113-3h7e</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-113-3h7e</guid>
      <description>&lt;p&gt;The task is to implement _.get().&lt;/p&gt;

&lt;p&gt;The boilerplate 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 get(source, path, defaultValue = undefined) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;_.get() is a handy method for retrieving data from an arbitrary object.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;source&lt;/code&gt; is the Object being read. &lt;code&gt;path&lt;/code&gt; is where to look. &lt;code&gt;defaultValue&lt;/code&gt; is where to return to if lookup fails.&lt;/p&gt;

&lt;p&gt;If the source does not exist, return the value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(source === null) return defaultValue;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the path is empty or invalid, return the default value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(path === null || (Array.isArray(path) &amp;amp;&amp;amp; path.length === 0) || path === '') {
    return defaultValue;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Normalise the path&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pathArray = Array.isArray(path)
  ? path
  : path
      .replace(/\[(\w+)\]/g, '.$1')
      .replace(/^\./, '')
      .split('.');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Traverse the object one key at a time&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = source;

for (let key of pathArray) {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the property cannot be read or the property does not exist, return the default value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (result === null || !(key in result)) {
  return defaultValue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the result to the next nested value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;result = result[key];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return the final value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return result
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 get(source, path, defaultValue = undefined) {
  // your code here
  if(source === null) return defaultValue;

  if(path === null || (Array.isArray(path) &amp;amp;&amp;amp; path.length === 0) || path === '') {
    return defaultValue;
  }

  const pathArray = Array.isArray(path) ? path 
  : path
        .replace(/\[(\w+)\]/g, '.$1')
        .replace(/^\./, '') 
        .split('.');

  let result = source;

  for(let key of pathArray) {
    if(result === null || !(key in result)) {
      return defaultValue;
    }
    result = result[key];
  }
  return result;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 112</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Mon, 02 Feb 2026 15:43:22 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-112-59p5</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-112-59p5</guid>
      <description>&lt;p&gt;The task is to implement setInterval.&lt;/p&gt;

&lt;p&gt;the boilerplate 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 mySetInterval(func, delay, period) {
  // your code here
}

/**
 * @param { number } id
 */
function myClearInterval(id) {

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

&lt;/div&gt;



&lt;p&gt;Create the global states&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let nextId = 1;
const intervals = new Map()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;nextId&lt;/code&gt; simulates browser-generated interval IDs and &lt;code&gt;intervals&lt;/code&gt; keep track of active intervals.&lt;/p&gt;

&lt;p&gt;Create a progressive interval&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func mySetInterval(func, delay, period) {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an ID&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const id = nextId++;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It ensures every interval has a unique identifier. &lt;/p&gt;

&lt;p&gt;Create an interval state&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const state = {
  active: true,
  count: 0,
  timeoutId: null
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;active&lt;/code&gt; stops future executions when cleared. &lt;code&gt;count&lt;/code&gt; is the number of times the function has been run. &lt;code&gt;timeoutId&lt;/code&gt; is the current setTimeout reference.&lt;/p&gt;

&lt;p&gt;Each period after every time the function runs is determined by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const waitTime = delay + period * state.count;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execute and reschedule&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;state.timeoutId = setTimeout(() =&amp;gt; {
  if (!state.active) return;

  func();
  state.count++;
  schedule();
}, waitTime);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the first timer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;schedule();
intervals.set(id, state);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return ID&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To clear the interval after it runs&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myClearInterval(id) {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the interval doesn't exist, do nothing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const state = intervals.get(id);
if (!state) return;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stop future executions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;state.active = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cancel pending timeout&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;clearTimeout(state.timeoutId);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove the interval from tracking&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;intervals.delete(id);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let nextId = 1;
const intervals = new Map();
function mySetInterval(func, delay, period) {
  // your code here
  const id = nextId++;

  const state = {
    active: true,
    count: 0,
    timeoutId: null
  }

  function schedule() {
    const waitTime = delay + period * state.count;

    state.timeoutId = setTimeout(() =&amp;gt; {
      if(!state.active) return;

      func();
      state.count++;
      schedule();
    }, waitTime)
  }

  schedule();
  intervals.set(id, state);

  return id;
}


function myClearInterval(id) {
  const state = intervals.get(id);
  if(!state) return;

  state.active = false;
  clearTimeout(state.timeoutId);
  intervals.delete(id)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>coding</category>
      <category>devchallenge</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 111</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Sun, 01 Feb 2026 22:35:46 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-111-5849</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-111-5849</guid>
      <description>&lt;p&gt;The task is to implement Math.sqrt().&lt;/p&gt;

&lt;p&gt;The boilerplate 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 mySqrt(x) {
  // your code here   
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Convert whatever is input to a number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const num = Number(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the input is negative or invalid, return NaN&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(isNaN(num)) {
 return NaN
}

if(num &amp;lt; 0) {
return NaN
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the input is 0 or 1, the square root is itself&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(num &amp;lt; 2) return num;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Binary search will be used to find the square root between 1 and the input&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let left = 1;
let right = Math.floor((left + right) / 2);
let ans = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For any number greater than or equal to 2, the square root is less than or equal to half the number. That's why the upper boundary for the search is at half of the number; the square root can't be bigger than that. &lt;/p&gt;

&lt;p&gt;To implement binary search, find the middle point of the search range&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while(left &amp;lt;= right) {
const mid = Math.floor((left + right) / 2);
const square = mid * mid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the square is equal to the original value, the middle point is the square root&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (square === num) {
 return mid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the square is less than the original value, search the right half. Otherwise, search the left half.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;else if(square &amp;lt; num) {
    ans = mid;    
    left = mid + 1; 
  } else {
    right = mid - 1;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 mySqrt(x) {
  // your code here  
  const num = Number(x);

  if(isNaN(num)) {
    return NaN;
  }

  if(num &amp;lt; 0) {
    return NaN;
  }

  if(num &amp;lt; 2) return x;

  let left = 1;
  let right = Math.floor(num / 2);
  let ans = 0;

  while(left &amp;lt;= right) {
    const mid = Math.floor((left + right) / 2);
    const square =  mid * mid;

    if(square === num) {
      return mid;
    } else if(square &amp;lt; num) {
      ans = mid;
      left = mid + 1;
    } else {
      right = mid - 1;
    }
    }
  return ans;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>coding</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 110</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Sat, 31 Jan 2026 22:47:02 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-110-4l7h</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-110-4l7h</guid>
      <description>&lt;p&gt;The task is to implement String.prototype.trim().&lt;/p&gt;

&lt;p&gt;The boilerplate 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 trim(str) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialise pointers to move inwards till they hit a whitespace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let start = 0;
let end = str.length - 1;

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

&lt;/div&gt;



&lt;p&gt;Trim leading whitespace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (start &amp;lt;= end &amp;amp;&amp;amp; /\s/.test(str[start])) {
  start++;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;\s&lt;/code&gt; matches all types of whitespace characters - spaces, tabs, newlines. &lt;/p&gt;

&lt;p&gt;Trim ending whitespace&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (end &amp;gt;= start &amp;amp;&amp;amp; /\s/.test(str[end])) {
  end--;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extract the trimmed string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return str.slice(start, end + 1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 trim(str) {
  // your code here
  let start = 0;
  let end = str.length - 1;

  while(start &amp;lt;= end &amp;amp;&amp;amp; /\s/.test(str[start])) {
    start++;
  }

  while(end &amp;gt;= start &amp;amp;&amp;amp; /\s/.test(str[end])) {
    end--;
  }
  return str.slice(start, end + 1) 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>coding</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Coding Challenge Practice - Question 109</title>
      <dc:creator>Bukunmi Odugbesan</dc:creator>
      <pubDate>Fri, 30 Jan 2026 16:25:04 +0000</pubDate>
      <link>https://dev.to/tomivan/coding-challenge-practice-question-109-3m02</link>
      <guid>https://dev.to/tomivan/coding-challenge-practice-question-109-3m02</guid>
      <description>&lt;p&gt;The task is to implement a function that converts snake case to camel case.&lt;/p&gt;

&lt;p&gt;The boilerplate 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 snakeToCamel(str) {
  // your code here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To convert from snake_case to camelCase, it is required that the connecting underscore be removed and the next word has its first letter capitalised. Leading underscores, trailing underscores and double underscores should be kept.&lt;/p&gt;

&lt;p&gt;Initialize variables to build the final string and a pointer to walk through the string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let result = '';
let i = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Loop through the string manually&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (i &amp;lt; str.length)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Determine the conditions that ensure only underscores that connect words are removed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (
  str[i] === '_' &amp;amp;&amp;amp;
  i &amp;gt; 0 &amp;amp;&amp;amp;
  i &amp;lt; str.length - 1 &amp;amp;&amp;amp;
  /[a-zA-Z]/.test(str[i + 1]) &amp;amp;&amp;amp;
  str[i - 1] !== '_'
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Convert the next character correctly. If it is lowercase, convert to uppercase. If it is uppercase, leave it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const nextChar = str[i + 1];

result += nextChar &amp;gt;= 'a' &amp;amp;&amp;amp; nextChar &amp;lt;= 'z'
  ? nextChar.toUpperCase()
  : nextChar;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Skip the underscore and the next character&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i += 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy as-is if there is no underscore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;else {
  result += str[i];
  i++;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Return the final string&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return result;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final 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 snakeToCamel(str) {
  // your code here
 let result = "";
 let i = 0;

 while(i &amp;lt; str.length) {
  if(str[i] === '_' &amp;amp;&amp;amp; i &amp;gt; 0 &amp;amp;&amp;amp; i &amp;lt; str.length - 1 &amp;amp;&amp;amp;  /[a-zA-Z]/.test(str[i + 1]) &amp;amp;&amp;amp; str[i - 1] !== '_') {
   const nextChar = str[i + 1];
   result += nextChar &amp;gt;= 'a' &amp;amp;&amp;amp; nextChar &amp;lt;= 'z' ? nextChar.toUpperCase() : nextChar;
   i += 2;
  } else {
    result += str[i];
    i++;
  }
 }
 return result;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all folks!&lt;/p&gt;

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