<?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: Nubian</title>
    <description>The latest articles on DEV Community by Nubian (@iam_kyei).</description>
    <link>https://dev.to/iam_kyei</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%2F305008%2Fd1e1014e-d35f-48e6-9a29-98b34bb9eaf1.jpg</url>
      <title>DEV Community: Nubian</title>
      <link>https://dev.to/iam_kyei</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iam_kyei"/>
    <language>en</language>
    <item>
      <title>LeetCode 30 Days of JavaScript — Day 1: Closures &amp; Counter Function</title>
      <dc:creator>Nubian</dc:creator>
      <pubDate>Fri, 11 Jul 2025 07:45:19 +0000</pubDate>
      <link>https://dev.to/iam_kyei/leetcode-30-days-of-javascript-day-1-closures-counter-function-4on3</link>
      <guid>https://dev.to/iam_kyei/leetcode-30-days-of-javascript-day-1-closures-counter-function-4on3</guid>
      <description>&lt;p&gt;Today I started the LeetCode 30 Days of JavaScript challenge, and Day 1 is all about closures — a core concept in JavaScript — with a simple but insightful problem:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem&lt;/strong&gt;&lt;br&gt;
Given an integer n, return a counter function.&lt;/p&gt;

&lt;p&gt;This counter function should initially return n and then return 1 more than the previous value every time it is called.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const counter = createCounter(10);
counter(); // 10
counter(); // 11
counter(); // 12

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

&lt;/div&gt;



&lt;p&gt;So the task is to implement the createCounter function that returns a function with memory — a perfect use case for closures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My solution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * @param {number} n
 * @return {Function} counter
 */
var createCounter = function (n) {
    return function counter() {
        return n++;
    };
};

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How it works&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The outer function
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var createCounter = function (n) {

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This function takes an initial number n.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside it, we return a new function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.The inner function (the closure)&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 counter() {
    return n++;
};

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;This is the function that we’ll call later: counter().&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Even though createCounter has already finished running, the inner counter function still remembers the variable n from its outer scope.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Every time we call counter(), it returns n and then increments n for the next call.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Example Run
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const counter = createCounter(10);

console.log(counter()); // 10
console.log(counter()); // 11
console.log(counter()); // 12

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

&lt;/div&gt;



&lt;p&gt;Here’s what happens:&lt;br&gt;
✅ First call → returns 10, then increments n to 11.&lt;br&gt;
✅ Second call → returns 11, then increments n to 12.&lt;br&gt;
✅ Third call → returns 12, then increments n to 13.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is this a closure?&lt;/strong&gt;&lt;br&gt;
Because:&lt;/p&gt;

&lt;p&gt;A closure is a function that “closes over” (remembers) the variables from the scope where it was created, even after that scope is gone.&lt;/p&gt;

&lt;p&gt;Here, the returned counter function retains access to n from createCounter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What I learned&lt;/strong&gt;&lt;br&gt;
Closures are simple but powerful.&lt;/p&gt;

&lt;p&gt;You can use closures to encapsulate state without polluting the global scope.&lt;/p&gt;

&lt;p&gt;Understanding this pattern is key to solving many JavaScript interview and coding challenge problems.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>leetcode</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>React Componets</title>
      <dc:creator>Nubian</dc:creator>
      <pubDate>Mon, 03 Jul 2023 07:56:40 +0000</pubDate>
      <link>https://dev.to/iam_kyei/react-componets-2kkm</link>
      <guid>https://dev.to/iam_kyei/react-componets-2kkm</guid>
      <description>&lt;p&gt;React components consist of three main parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
Data:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Data includes the state and props of the component.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;State represents data that can be updated by the component's logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Props (short for properties) are used to pass data from a parent component to a child component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The parent component controls how the child component should look or behave through props.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Props are data that comes from the outside and can only be updated by the parent component. The parent component owns the data and transfers it to the child components.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;
Logic:
The logic of a component refers to the code that handles the component's behavior and functionality.
It includes functions, event handlers, and any other operations that manipulate or process data.
3.
View (UI):
The view, or UI (User Interface), represents the visual part of the component that users interact with.
It includes elements, styles, and layout configurations that define how the component appears on the screen.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;React follows a one-way data flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Data flows from the parent component to its child components through props.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Child components cannot directly modify the data received via props; they can only read and display it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a child component needs to update data, it should communicate with its parent component by triggering events or callbacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The parent component can then modify its own state based on these events and pass the updated data down to its child components again.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By separating data, logic, and view, React components promote a modular and reusable structure, making it easier to build complex user interfaces.&lt;/p&gt;

&lt;p&gt;Here is a working example of a Profile Card from Jonas Schmedtmann's React Course Challenge, Problem #1, and I solved. Sandbox Link below &lt;br&gt;
&lt;a href="https://codesandbox.io/s/jonas-react-course-section-5-ndxtcs"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>30daysofreact</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
