<?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: ckorley4</title>
    <description>The latest articles on DEV Community by ckorley4 (@ckorley4).</description>
    <link>https://dev.to/ckorley4</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%2F1248182%2Fe6a7dd57-15b4-4480-ae10-e24c7c02470b.jpeg</url>
      <title>DEV Community: ckorley4</title>
      <link>https://dev.to/ckorley4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ckorley4"/>
    <language>en</language>
    <item>
      <title>Encapsulation in Python</title>
      <dc:creator>ckorley4</dc:creator>
      <pubDate>Fri, 29 Mar 2024 14:54:08 +0000</pubDate>
      <link>https://dev.to/ckorley4/encapsulation-in-python-1gk2</link>
      <guid>https://dev.to/ckorley4/encapsulation-in-python-1gk2</guid>
      <description>&lt;p&gt;The process of wrapping up variables and methods into a single entity is known as Encapsulation. It is one of the underlying concepts in object-oriented programming (OOP). It acts as a protective shield that puts restrictions on accessing variables and methods directly, and can prevent accidental or unauthorized modification of data. Encapsulation also makes objects into more self-sufficient, independently functioning pieces.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do we need Encapsulation in Python?&lt;/strong&gt;&lt;br&gt;
The advantages of Encapsulation in Python can be summed up as follows –&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Encapsulation provides well-defined, readable code&lt;br&gt;
The primary advantage of using Encapsulation in Python is that as a user, we do not need to know the architecture of the methods and the data and can just focus on making use of these functional, encapsulated units for our applications. This results in a more organized and clean code. The user experience also improves greatly and makes it easier to understand applications as a whole.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prevents Accidental Modification or Deletion&lt;br&gt;
Another advantage of encapsulation is that it prevents the accidental modification of the data and methods. Let’s consider the example of NumPy again, if I had access to edit the library, then I might make a mistake in the implementation of the mean function and then because of that mistake, thousands of projects using NumPy would become inaccurate.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Encapsulation provides security&lt;br&gt;
Encapsulation in Python is achieved through the access modifiers. These access modifiers ensure that access conditions are not breached and thus provide a great user experience in terms of security.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Encapsulation provides reusability&lt;br&gt;
It is easier to reuse code when it is encapsulated. Creating objects that contain common functionality allows us to reuse them in many settings.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Access Modifiers in Python encapsulation&lt;br&gt;
Sometimes there might be a need to restrict or limit access to certain variables or functions while programming. That is where access modifiers come into the picture.&lt;/p&gt;

&lt;p&gt;Now when we are talking about access, 3 kinds of access specifiers can be used while performing Encapsulation in Python. They are as follows :&lt;/p&gt;

&lt;p&gt;Public Members&lt;br&gt;
Private Members&lt;br&gt;
Protected Members&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg9mp02ow61v4zj7hgkq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg9mp02ow61v4zj7hgkq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets take a look at this example&lt;/p&gt;

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

# Encapsulation in Python
# A simple example

class Original: 
    def __init__(self): 
        self._protected_variable= 10

# Creating a derived class 
class Derived(Original): 
    def __init__(self): 

        # Calling constructor of  Original Class
        Original.__init__(self) 
        print("Calling the member of the original class: ",  
              self._protected_variable) 

        # Modifying the protected variable: 
        self._protected_variable = 200
        return(f'Protected member outside class:{self._protected_variable}') 

object_one = Derived() 
object_two = Original() 

print("Protected member of Derived: ", object_one._protected_variable) 

print("Protected member of Original: ", object_two._protected_variable) 


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Encapsulation in Python refers to the practice of hiding the implementation details of an object or class, and only exposing a public interface for interacting with it.&lt;/p&gt;

&lt;p&gt;Encapsulation is achieved through the use of access modifiers such as 'public', 'private', and 'protected'.&lt;/p&gt;

&lt;p&gt;Variables and methods declared with the 'private' or 'protected' access modifiers are not accessible from outside the class, while those declared as 'public' are.&lt;/p&gt;

&lt;p&gt;Encapsulation helps to promote code reusability, maintainability, and security by preventing external code from accessing or modifying the internal state of an object or class.&lt;/p&gt;

&lt;p&gt;The '&lt;em&gt;' or '&lt;/em&gt;_' prefix can be used to indicate a variable or method as private, however, it is not enforced by the interpreter and can still be accessed.&lt;/p&gt;

&lt;p&gt;In Python, encapsulation is not as strict as in other languages such as Java, as it does not have the concept of protected variables and methods.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.educative.io/answers/what-is-encapsulation-in-python" rel="noopener noreferrer"&gt;https://www.educative.io/answers/what-is-encapsulation-in-python&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.scaler.com/topics/python/encapsulation-in-python/" rel="noopener noreferrer"&gt;https://www.scaler.com/topics/python/encapsulation-in-python/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Memoization in Python; an alternative to Recursion</title>
      <dc:creator>ckorley4</dc:creator>
      <pubDate>Sat, 17 Feb 2024 09:37:48 +0000</pubDate>
      <link>https://dev.to/ckorley4/memoization-in-python-an-alternative-to-recursion-30km</link>
      <guid>https://dev.to/ckorley4/memoization-in-python-an-alternative-to-recursion-30km</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
One of the most effective recipes for solving Dynamic Programming problems is Memoization.&lt;br&gt;
Memoization is the process of storing the result of the subproblem and calling them again when a similar subproblem is to be solved. This will reduce the time complexity of the problem. If we do not use memorization, similar subproblems are repeatedly solved which can lead to exponential time complexities.&lt;/p&gt;

&lt;p&gt;Memorization has one major advantage over conventional computation techniques: it can drastically cut down on the time and resources needed to compute a function’s output. This is especially helpful when dealing with functions that perform repetitive tasks or have a high computational cost. The program can execute more quickly by avoiding the overhead of repeatedly computing the same result by caching the output of these functions.&lt;/p&gt;

&lt;p&gt;Memoization is useful in various Python programming applications, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recursive functions that call themselves with the same input values&lt;/li&gt;
&lt;li&gt;Computationally intensive functions, such as mathematical functions&lt;/li&gt;
&lt;li&gt;Functions that retrieve data from a remote source or database&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Factorial&lt;/strong&gt;&lt;br&gt;
Let's look a simple example if recursion. The example below uses recursion to compute the factorial of a number. eg.(200)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def factorial(input):
    if input &amp;lt; 2: 
        return 1
    elif input &amp;gt;= 2:
        return input * factorial(input-1)

print(factorial(200))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Memoization&lt;/strong&gt;&lt;br&gt;
Lets look at the same example with Memoization&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;memo ={}
def memoized(n):
    if n in memo:
        return memo[n]
    elif n == 0:
        return 1
    else:
        x = fact(n-1) * n
        memo[n] = x
        return x
print(memoized(200))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>Drilling in React</title>
      <dc:creator>ckorley4</dc:creator>
      <pubDate>Fri, 26 Jan 2024 20:47:47 +0000</pubDate>
      <link>https://dev.to/ckorley4/drilling-in-react-2hfm</link>
      <guid>https://dev.to/ckorley4/drilling-in-react-2hfm</guid>
      <description>&lt;p&gt;Props are used by react to pass information from one component to another&lt;/p&gt;

&lt;p&gt;There are situations that require information to go from Parent component to child component and to Grandchildren &lt;/p&gt;

&lt;p&gt;How to avoid prop drilling&lt;br&gt;
In case, when you project become larger and more complex, prop drilling can become a problem. To avoid this problem in React-based projects, there are several patterns and techniques that can be used:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Context&lt;/strong&gt;&lt;br&gt;
React Context is a way to share data across the component hierarchy without passing it down explicitly as props. Context can be a good alternative to prop drilling when you need to share data across multiple components.&lt;br&gt;
The problem with Prop Drilling is that whenever data from the Parent component will be needed, it would have to come from each level, Regardless of the fact that it is not needed there and simply needed in last.&lt;/p&gt;

&lt;p&gt;With Context, you can define data at the top level of the component tree and then access it anywhere in the tree. This can help reduce the amount of code you need to write, and make it easier to manage and share data across the component hierarchy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Drawbacks of Drilling&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Code Complexity&lt;/strong&gt;&lt;br&gt;
As components grow, prop drilling increases code complexity as it is difficult to track the flow of data through various components.&lt;br&gt;
&lt;strong&gt;Reduced Maintainability&lt;/strong&gt; &lt;br&gt;
It will become very challenging to maintain the code with prop drilling. When changes are required in the data flow, you need to make changes in many components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance Overhead&lt;/strong&gt; We have to pass props through unnecessary intermediary components which can impact performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decreased Component Reusability&lt;/strong&gt;&lt;br&gt;
Components used in prop drilling become tightly coupled to the structure of the parent components, so it very difficult to use it on other parts of the application.&lt;br&gt;
Increased Development Time: Prop drilling often requires additional planning to implement. This can slow down the development process, especially when the component hierarchies is complex.&lt;/p&gt;

&lt;p&gt;A better alternative to this is using useContext hook. The useContext hook is based on Context API and works on the mechanism of Provider and Consumer. Provider needs to wrap components inside Provider Components in which data have to be consumed. Then in those components, using the useContext hook that data needs to be consumed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/what-is-prop-drilling-and-how-to-avoid-it/"&gt;https://www.geeksforgeeks.org/what-is-prop-drilling-and-how-to-avoid-it/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://javascript.plainenglish.io/prop-drilling-in-react-understanding-the-benefits-and-pitfalls-of-passing-props-down-the-component-fcf9887f8b73"&gt;https://javascript.plainenglish.io/prop-drilling-in-react-understanding-the-benefits-and-pitfalls-of-passing-props-down-the-component-fcf9887f8b73&lt;/a&gt;&lt;/p&gt;

</description>
      <category>props</category>
      <category>drilling</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Recursion, A Beginner's guide</title>
      <dc:creator>ckorley4</dc:creator>
      <pubDate>Wed, 10 Jan 2024 14:23:52 +0000</pubDate>
      <link>https://dev.to/ckorley4/recursion-a-beginners-guide-3ifh</link>
      <guid>https://dev.to/ckorley4/recursion-a-beginners-guide-3ifh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Intronduction&lt;/strong&gt;&lt;br&gt;
Recursion is used to solve problems that contain smaller sub-problems.When a function calls itself, recusion has occurred. A recursive function can receive two inputs: a base case (ends recursion) or a recursive case (resumes recursion).&lt;/p&gt;

&lt;p&gt;Lets look at an example of traversing a complex object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;came&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Thomas&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;school&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Flat Schools&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;jobTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Developer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;friends&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Ama&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;school&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Carlifornia Low&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;jobTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Programmer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Nii&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;school&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New York High&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;jobTitle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Lead Developer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;assignments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Draw&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Draw the map of the world.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Paint&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Paint a statue in your neighborhood.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Traversing the &lt;code&gt;userInfo&lt;/code&gt; Object with a recursive function requires the Base case and the Recursive case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;resursionExample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;deepIterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Base Case&lt;/strong&gt;&lt;br&gt;
The base case of a recursive function returns a value without performing a recursive call.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Recursive case&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;resursionExample&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;deepIterator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Recursion Pitfalls&lt;/strong&gt;&lt;br&gt;
A common pitfall when designing recursive algorithms include not defining a base case.This will lead to causing infinite recursion, and inefficient memory usage.&lt;/p&gt;

&lt;p&gt;Recursive algorithms can be less efficient than their iterative counterparts. This is because each recursive call involves overhead, such as saving the state of the current function and setting up the new function. In contrast, iterative algorithms use a loop to repeat operations, which can be faster and use less memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Recursive function may be easier to write and reduces unnecessary  function calling.&lt;br&gt;
Despite these benefits Recursive functions are generally slower than non-recursive function and may require a lot of memory space to hold intermediate results on the system stacks.&lt;br&gt;
The programmer must evaluate a problem thoroughly before choose to write a recursive function&lt;/p&gt;

&lt;p&gt;References&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Recursion"&gt;https://developer.mozilla.org/en-US/docs/Glossary/Recursion&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.tutorchase.com/answers/ib/computer-science/what-are-common-pitfalls-when-designing-recursive-algorithms"&gt;https://www.tutorchase.com/answers/ib/computer-science/what-are-common-pitfalls-when-designing-recursive-algorithms&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.archilovers.com/stories/5232/the-8-most-extraordinary-spiral-staircases-found-around-the-world.html"&gt;https://www.archilovers.com/stories/5232/the-8-most-extraordinary-spiral-staircases-found-around-the-world.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.collegenote.net/curriculum/data-structures-and-algorithms/41/454/"&gt;https://www.collegenote.net/curriculum/data-structures-and-algorithms/41/454/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
