<?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: Olaide Emmanuel</title>
    <description>The latest articles on DEV Community by Olaide Emmanuel (@delaquash).</description>
    <link>https://dev.to/delaquash</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%2F1175201%2F2ff7acba-3b6b-4cbb-b559-19955e561d99.jpeg</url>
      <title>DEV Community: Olaide Emmanuel</title>
      <link>https://dev.to/delaquash</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/delaquash"/>
    <language>en</language>
    <item>
      <title>Exploring Essential Promise Methods in JavaScript.</title>
      <dc:creator>Olaide Emmanuel</dc:creator>
      <pubDate>Mon, 17 Mar 2025 11:39:02 +0000</pubDate>
      <link>https://dev.to/delaquash/exploring-essential-promise-methods-in-javascript-2p7j</link>
      <guid>https://dev.to/delaquash/exploring-essential-promise-methods-in-javascript-2p7j</guid>
      <description>&lt;p&gt;When working with asynchronous operations in JavaScript, Promises provide a robust way to handle multiple asynchronous tasks efficiently. Before diving into async/await, it's essential to understand some core Promise methods:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Promise.all()&lt;/li&gt;
&lt;li&gt;Promise.any()&lt;/li&gt;
&lt;li&gt;Promise.race()&lt;/li&gt;
&lt;li&gt;Promise.finally()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's explore each method in detail with examples.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;## Promise.all() &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Promise.all() method accepts an iterable (e.g., an array of promises) and returns a single promise that resolves to an array containing results of all input promises.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Key Characteristics:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Resolves only when all promises in the array are fulfilled.&lt;/p&gt;

&lt;p&gt;Rejects immediately if any promise in the array is rejected.&lt;/p&gt;

&lt;p&gt;Useful when executing multiple asynchronous operations that must complete before proceeding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const promise1 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 300, "resolved1"));
const promise2 = 93; // Non-promise value
const promise3 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 100, "resolved2"));

Promise.all([promise1, promise2, promise3])
  .then((values) =&amp;gt; console.log(values))
  .catch((error) =&amp;gt; console.log(error));

// Expected output: [ 'resolved1', 93, 'resolved2' ]

## Rejection Behavior:

## If any promise in the array rejects, Promise.all() immediately rejects with that error.
const p1 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 1000, "one"));
const p2 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 2000, "two"));
const p3 = new Promise((_, reject) =&amp;gt; setTimeout(reject, 3000, "rejected"));

Promise.all([p1, p2, p3])
  .then((values) =&amp;gt; console.log(values))
  .catch((error) =&amp;gt; console.log(error));

// Expected output: "rejected"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Promise.any()&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Promise.any() method takes an iterable of promises and returns the first fulfilled promise. If none of the promises resolve, it rejects with an AggregateError.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Key Characteristics:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Resolves as soon as one promise fulfills.&lt;/p&gt;

&lt;p&gt;If all promises reject, it returns an AggregateError.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fastPromise = new Promise((resolve) =&amp;gt; setTimeout(resolve, 100, "Done quickly"));
const slowPromise = new Promise((resolve) =&amp;gt; setTimeout(resolve, 500, "Done slowly"));
const rejectedPromise = new Promise((_, reject) =&amp;gt; setTimeout(reject, 100, "Rejected"));

Promise.any([fastPromise, slowPromise, rejectedPromise])
  .then((value) =&amp;gt; console.log(value))
  .catch((err) =&amp;gt; console.log(err));

// Expected output: "Done quickly"
// This is when Promise.any() throws a rejection error.

const rejected = new Promise((_, reject) =&amp;gt; setTimeout(reject, 100, "Rejected"));

Promise.any([rejected])
  .catch((err) =&amp;gt; console.log(err));

// Expected output: "AggregateError: No Promise in Promise.any was resolved"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Promise.finally()&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The finally() method executes a callback regardless of promise resolution or rejection. It is useful for cleanup operations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Key Characteristics:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Runs the provided callback function regardless of whether the promise resolves or rejects.&lt;/p&gt;

&lt;p&gt;Does not modify the resolved or rejected value.&lt;/p&gt;

&lt;p&gt;Useful for tasks like closing a loader, resetting states, or releasing resources.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const addNumbers = (a, b) =&amp;gt; new Promise((resolve, reject) =&amp;gt; {
  if (typeof a === "number" &amp;amp;&amp;amp; typeof b === "number") {
    resolve(a + b);
  } else {
    reject("Not a Number");
  }
});

addNumbers(10, 5)
  .then((result) =&amp;gt; console.log(result))
  .catch((error) =&amp;gt; console.log(error))
  .finally(() =&amp;gt; console.log("Operation complete"));

/* Expected output:15
   Operation complete
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Promise.race()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Promise.race() method returns a promise that resolves or rejects as soon as one of the promises settles.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Key Characteristics:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Resolves with the first settled promise's value.&lt;/p&gt;

&lt;p&gt;If a promise rejects first, the rejection is returned immediately.&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 p1 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 200, "one"));
const p2 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 100, "two"));

Promise.race([p1, p2])
  .then((response) =&amp;gt; console.log(response))
  .catch((err) =&amp;gt; console.log(err));

// Expected output: "two"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const p3 = new Promise((_, reject) =&amp;gt; setTimeout(reject, 300, "rejected"));
const p4 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 400, "four"));

Promise.race([p3, p4])
  .then((response) =&amp;gt; console.log(response))
  .catch((err) =&amp;gt; console.log(err));

// Expected output: "rejected"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Handling rejections in Promise.race() can be simplified to this explanation below:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Promise.race() resolves or rejects as soon as the first promise settles.&lt;/li&gt;
&lt;li&gt;If the first settled promise resolves, race() resolves with its value.&lt;/li&gt;
&lt;li&gt;If the first settled promise rejects, race() rejects immediately.&lt;/li&gt;
&lt;li&gt;The remaining promises are ignored once one settles.&lt;/li&gt;
&lt;li&gt;This behavior makes Promise.race() useful for timeouts and early exits.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const p3 = new Promise((_, reject) =&amp;gt; setTimeout(reject, 300, "rejected"));
const p4 = new Promise((resolve) =&amp;gt; setTimeout(resolve, 400, "four"));

Promise.race([p3, p4])
  .then((response) =&amp;gt; console.log(response))
  .catch((err) =&amp;gt; console.log(err));

// Expected output: "rejected"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding Promise.all(), Promise.any(), Promise.race(), and Promise.finally() is essential for writing efficient asynchronous code in JavaScript. These methods provide different approaches to handling multiple promises, allowing developers to manage tasks effectively.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Structuring and Architecting Your React Native Mobile Application.</title>
      <dc:creator>Olaide Emmanuel</dc:creator>
      <pubDate>Mon, 17 Feb 2025 10:51:19 +0000</pubDate>
      <link>https://dev.to/delaquash/structuring-and-architecting-your-react-native-mobile-application-5682</link>
      <guid>https://dev.to/delaquash/structuring-and-architecting-your-react-native-mobile-application-5682</guid>
      <description>&lt;p&gt;In software development, the architecture of an application significantly impacts its maintainability, scalability, and overall development experience. When structuring a React or React Native app, different design patterns, principles, and approaches come into play.&lt;/p&gt;

&lt;p&gt;This article explores key principles such as modularization, abstraction, and encapsulation and how they enhance app structure. We will also discuss useful tools and patterns for achieving these principles in React Native applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;1. Modularization&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Modularization involves breaking down a large application into smaller, self-contained modules that can be developed, tested, and maintained independently.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
i. Improved Code Efficiency: Promotes code reuse across multiple screens and sections.&lt;br&gt;
ii. Enhanced Scalability: Enables easy feature expansion without disrupting existing code.&lt;br&gt;
iii. Separation of Concerns: Improves readability, maintainability, and debugging.&lt;br&gt;
iv. Collaborative Workflows: Allows multiple developers to work simultaneously on different modules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Patterns for Achieving Modularization
&lt;/h2&gt;

&lt;p&gt;Single Responsibility Principle_**: Each module should have one &lt;br&gt;
 responsibility.&lt;/p&gt;

&lt;p&gt;Component-Based Architecture_**: Encourages reusable and independent &lt;br&gt;
 components.&lt;/p&gt;

&lt;p&gt;Directory Structure: Organize project files systematically (screens, &lt;br&gt;
 components, utilities, etc.).&lt;/p&gt;

&lt;p&gt;Clear Interfaces_**: Define APIs to promote loose coupling.&lt;/p&gt;

&lt;p&gt;Unit Testing_**: Validate module functionality.&lt;/p&gt;

&lt;p&gt;Documentation_**: Clearly describe each module’s purpose and usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;2. Abstraction&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Abstraction simplifies complex systems by focusing on essential features while hiding unnecessary details, improving code readability and flexibility.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;i. Simplicity: Hides complexity and makes code easier to understand.&lt;/p&gt;

&lt;p&gt;ii. Reusability: Encourages the reuse of components across the app.&lt;/p&gt;

&lt;p&gt;iii. Maintainability: Allows changes in one place without affecting other areas.&lt;/p&gt;

&lt;p&gt;iv. Readability: Provides clean and concise interfaces.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Patterns for Achieving Abstraction&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Abstract Classes and Interfaces&lt;/strong&gt;&lt;/em&gt;: Define shared functionality for components.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Reusable Functionality Extraction&lt;/strong&gt;&lt;/em&gt;: Modularize common logic.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Higher-Order Components (HOCs)&lt;/strong&gt;&lt;/em&gt;: Encapsulate common behaviors.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Custom Hooks&lt;/strong&gt;&lt;/em&gt;: Abstract and reuse business logic.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;API Abstraction&lt;/strong&gt;&lt;/em&gt;: Centralize API calls in a dedicated module.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Documentation&lt;/strong&gt;&lt;/em&gt;: Provide clear instructions on abstracted components.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;3. Encapsulation&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Encapsulation restricts direct access to a module’s internal data and methods, ensuring data integrity and security.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Patterns for Achieving Encapsulation&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;i. Avoid Prop Drilling: Use Context API, HOCs, or state management tools.&lt;/p&gt;

&lt;p&gt;ii. Use Prop Types: Enforce expected data structures.&lt;/p&gt;

&lt;p&gt;iii. Data Hiding: Protect internal state and only expose necessary data.&lt;/p&gt;

&lt;p&gt;iv. Component-Based Architecture: Ensure independent components.&lt;/p&gt;

&lt;p&gt;v.  Component Libraries: Promote reusable and modular components.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;4. Well Known Patterns&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Container-Component Pattern&lt;/p&gt;

&lt;p&gt;Containers: Handle state, API calls, and business logic.&lt;/p&gt;

&lt;p&gt;Components: Focus on UI rendering and user interaction.&lt;/p&gt;

&lt;p&gt;Component-Based Pattern&lt;/p&gt;

&lt;p&gt;Encourages breaking down UI elements into reusable components.&lt;/p&gt;

&lt;p&gt;Page Components&lt;/p&gt;

&lt;p&gt;Represent full screens with structured layouts and navigation.&lt;/p&gt;

&lt;p&gt;Feature Components&lt;/p&gt;

&lt;p&gt;Self-contained components handling specific features (e.g., Authentication, Error Boundaries).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;5. State Management&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;State management in React and React Native refers to handling and updating application data efficiently across components. It ensures UI consistency by managing local state using useState and useReducer, and global state using Context API, Redux Toolkit, or Zustand. For complex apps, Redux Toolkit is commonly used to centralize state logic, enabling better scalability and debugging. Efficient state management improves performance and ensures a smooth user experience.&lt;/p&gt;

&lt;p&gt;Consider using:&lt;/p&gt;

&lt;p&gt;i. Redux / Redux Toolkit / RTK Query for Large applications&lt;/p&gt;

&lt;p&gt;ii. MobX / Zustand:- The new cool kid in the building with all its shiny powers.&lt;/p&gt;

&lt;p&gt;iii. React Context API:- Good for small, medium and not too large applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;6. Folder Structure&lt;/em&gt;&lt;/strong&gt;:-
&lt;/h3&gt;

&lt;p&gt;A well-organized folder structure in a React Native app improves maintainability, scalability, and readability. &lt;/p&gt;

&lt;p&gt;Group by Feature or Functionality:&lt;/p&gt;

&lt;p&gt;│── android/               # Native Android project files&lt;br&gt;
│── ios/                   # Native iOS project files&lt;br&gt;
│── src/                   # Main source code&lt;br&gt;
│   │── components/        # Reusable UI components&lt;br&gt;
│   │── screens/           # Screens for navigation&lt;br&gt;
│   │── navigation/        # React Navigation setup&lt;br&gt;
│   │── store/             # State management (Redux/Zustand)&lt;br&gt;
│   │── hooks/             # Custom hooks&lt;br&gt;
│   │── services/          # API calls &amp;amp; external services&lt;br&gt;
│   │── utils/             # Utility/helper functions&lt;br&gt;
│   │── assets/            # Images, icons, fonts&lt;br&gt;
│   │── config/            # App configurations &amp;amp; constants&lt;br&gt;
│   │── styles/            # Global styles&lt;br&gt;
│   └── App.tsx            # Entry point&lt;br&gt;
│── .env                   # Environment variables&lt;br&gt;
│── package.json           # Project dependencies&lt;br&gt;
│── babel.config.js        # Babel configuration&lt;br&gt;
│── metro.config.js        # Metro bundler configuration&lt;br&gt;
│── index.js               # Entry file for React Native&lt;br&gt;
└── README.md              # Project documentation&lt;/p&gt;

&lt;p&gt;Avoid Over-Nesting: Maintain a balance between organization and simplicity.&lt;/p&gt;

&lt;p&gt;Use Index Files: Improve file imports and readability.&lt;/p&gt;

&lt;p&gt;Separate Configurations: Keep configuration files at the root level.&lt;/p&gt;

&lt;p&gt;Version Control: Implement Git for tracking changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;7. Testing&lt;/em&gt;&lt;/strong&gt; :-Testing in React Native ensures the reliability, performance, and
&lt;/h3&gt;

&lt;p&gt;correctness of your application. There are different levels of testing:&lt;/p&gt;

&lt;p&gt;a. Unit Testing: &lt;br&gt;
Testing Individual Components &amp;amp; Functions)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ensures that small pieces of code (like functions, hooks, or 
components) work as expected.
Tools: Jest (default test runner), React Native Testing Library
Example:

import { render } from "@testing-library/react-native";
import MyComponent from "../components/MyComponent";

test("renders MyComponent correctly", () =&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;{&lt;br&gt;
      const { getByText } = render();&lt;br&gt;
      expect(getByText("Hello World")).toBeTruthy();&lt;br&gt;
    });&lt;/p&gt;

&lt;p&gt;b. Integration Testing &lt;br&gt;
    Testing Combined Components &amp;amp; Logic&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ensures different parts of the app work together correctly.
Tools: React Native Testing Library, Jest
Example (Testing an API call inside a component):

import { render, waitFor } from "@testing-library/react-native";
import MyComponent from "../components/MyComponent";
import axios from "axios";

jest.mock("axios");

test("fetches and displays data", async () =&amp;gt; {
  axios.get.mockResolvedValue({ data: { message: "Hello World" } });
  const { getByText } = render(&amp;lt;MyComponent /&amp;gt;);
  await waitFor(() =&amp;gt; expect(getByText("Hello World")).toBeTruthy());
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;c. End-to-End (E2E) Testing (Simulating User Interactions)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tests the app as a user would by simulating clicks, navigation, and 
interactions.
Tools: Detox (for automation), Appium
Example (Detox Test):

describe("Login Flow", () =&amp;gt; {
  it("should login successfully", async () =&amp;gt; {
    await element(by.id("username")).typeText("user");
    await element(by.id("password")).typeText("password");
    await element(by.id("loginButton")).tap();
    await expect(element(by.id("homeScreen"))).toBeVisible();
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;8. Performance &amp;amp; Debugging Testing&lt;/em&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ensures app runs smoothly without memory leaks or slow performance.
Tools: React DevTools, Flipper, Xcode/Android Profiler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Best Practices for Testing in React Native&lt;/p&gt;

&lt;p&gt;✅ Write tests for critical features (authentication, API calls, UI interactions).&lt;br&gt;
✅ Use @testing-library/react-native for component testing.&lt;br&gt;
✅ Mock API responses using Jest to prevent network calls.&lt;br&gt;
✅ Automate E2E tests with Detox for real device testing.&lt;br&gt;
✅ Run tests in CI/CD pipelines (GitHub Actions, CircleCI).&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;A well-structured React Native app enhances scalability, maintainability, and overall development efficiency. By following principles like modularization, abstraction, and encapsulation, along with using best practices in state management, folder structure, testing, and CI/CD, you can build robust applications that stand the test &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>software</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>React Forms: Controlled and Uncontrolled Components.</title>
      <dc:creator>Olaide Emmanuel</dc:creator>
      <pubDate>Tue, 16 Jan 2024 10:36:41 +0000</pubDate>
      <link>https://dev.to/delaquash/react-forms-controlled-and-uncontrolled-components-3kcm</link>
      <guid>https://dev.to/delaquash/react-forms-controlled-and-uncontrolled-components-3kcm</guid>
      <description>&lt;p&gt;React provides developers with two main approaches to handling form data: controlled and uncontrolled forms. In most cases, the recommended method by the React teams for forms are the controlled method, although the uncontrolled method is still valid, it gives less flexibility compared to the controlled form.&lt;/p&gt;

&lt;h2&gt;
  
  
  Controlled Forms
&lt;/h2&gt;

&lt;p&gt;A controlled form in React is a form where the form elements (like input fields) are controlled by the state of the React component. In other words, the values of the form elements are stored in the component's state, and any changes to the form elements are handled by updating the state.&lt;/p&gt;

&lt;p&gt;React encourages the use of controlled components for forms, where the component state manages the values of form elements. The provided code snippet illustrates the concept of a controlled form using React hooks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ee6aE7ke--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xhj9ito4okzdmjkwj995.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ee6aE7ke--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xhj9ito4okzdmjkwj995.png" alt="React Controlled Form" width="800" height="992"&gt;&lt;/a&gt;&lt;br&gt;
In this example, the useState hook is employed to initialize a piece of state named value with an initial value of an empty string. The setValue function is later used to update this state.&lt;/p&gt;

&lt;p&gt;Input Element Binding&lt;br&gt;
The input element is bound to the value state, ensuring that its value is always controlled by the React component's state. The onChange event is connected to the handleChange function, which updates the state with the latest value as the user types.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of Controlled Forms
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Predictable State: The state of the form elements is predictable and can be easily managed by React.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Single Source of Truth: The component state serves as a single source of truth for the form data, making it easier to track and manage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic Updates: Reacting to user input is seamless, allowing for dynamic updates based on the component state.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Uncontrolled Forms
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TdAvR1Eq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrxvl63xjav5i9u83b4u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TdAvR1Eq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrxvl63xjav5i9u83b4u.png" alt="React Uncontrolled Form" width="800" height="612"&gt;&lt;/a&gt;&lt;br&gt;
In this example, an uncontrolled form is created using a combination of useRef and traditional HTML form elements. The inputRef is utilized to reference the DOM input element without managing its state through React.&lt;/p&gt;

&lt;h3&gt;
  
  
  Uncontrolled Form Characteristics
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;No React State Management: Unlike controlled forms where form elements are connected to React state, uncontrolled forms do not rely on state for managing form data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Direct DOM Interaction: The ref is used to directly access the DOM element, allowing developers to interact with the form elements without involving React state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No Event Listeners for Value Changes: Uncontrolled forms do not attach onChange event listeners to track input changes. Instead, the value is directly accessed when needed, as shown in the handleSubmit function.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Benefits of Uncontrolled Forms
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Simplicity: Uncontrolled forms are simpler and might be preferred for scenarios where React's state management is not necessary.&lt;/li&gt;
&lt;li&gt;Ref-Based Interaction: Directly interacting with the DOM through ref provides a straightforward way to access form data without the need for state updates.
Compatibility with Non-React Code:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Uncontrolled forms can be useful when integrating React into projects with existing non-React code, as they align more closely with traditional HTML forms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Considerations
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Limited React Features: Uncontrolled forms sacrifice some of React's powerful features, such as easy state management and dynamic updates.&lt;/li&gt;
&lt;li&gt;Validation and Testing: Implementing form validation and testing might be more challenging in uncontrolled forms compared to controlled ones.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Controlled forms provide a structured way to handle form data in React applications. By managing the form elements through component state, developers gain more control over the form's behavior and can easily integrate it with other React features.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>DevOps Learning Path</title>
      <dc:creator>Olaide Emmanuel</dc:creator>
      <pubDate>Thu, 11 Jan 2024 15:39:09 +0000</pubDate>
      <link>https://dev.to/delaquash/devops-learning-path-4lcg</link>
      <guid>https://dev.to/delaquash/devops-learning-path-4lcg</guid>
      <description>&lt;p&gt;This is my proposed learning curriculum for DevOps, and I am dropping this after extensive research on the best, free and paid resources that can be used to achieve this goal.&lt;/p&gt;

&lt;p&gt;DevOps is a software engineering methodology that aims to integrate the work of development and operations teams by facilitating a culture of collaboration and shared responsibility.&lt;/p&gt;

&lt;p&gt;It is a set of practices, tools, and a cultural philosophy that automate and integrate the processes between software development and IT teams. DevOps emphasizes team empowerment, cross-team communication and collaboration, and technology automation.&lt;/p&gt;

&lt;p&gt;It began some years back when the software development and IT operations communities raised concerns about the traditional software development model, where developers who wrote code worked apart from operations who deployed and supported the code.&lt;br&gt;
DevOps is an approach to culture, automation, and platform design intended to deliver increased business value and responsiveness through rapid, high-quality service delivery.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you will learn:-
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Continuous Integration and Delivery (CI/CD) practices, tools, concepts and how to set up a CI/CD pipeline using Jenkins or GitHub Actions.&lt;/li&gt;
&lt;li&gt;Cloud computing platforms like AWS, Azure, Google Cloud Platform and its pros and cons.&lt;/li&gt;
&lt;li&gt;Use of containerization technologies such as Docker &amp;amp; Kubernetes&lt;/li&gt;
&lt;li&gt;Monitoring and Logging Tools: Prometheus, Grafana.&lt;/li&gt;
&lt;li&gt;Microservices architecture principles and best practices&lt;/li&gt;
&lt;li&gt;Version Control Systems - Git, Github and/or Gitlab.&lt;/li&gt;
&lt;li&gt;Automated deployment using CI/CD tools like Jenkins etc.&lt;/li&gt;
&lt;li&gt;Infrastructure as Code (IaC) tools like Terraform, Ansible etc.&lt;/li&gt;
&lt;li&gt;Learn Linux OS and its CLI: Although Windows OS and MacOS can be used via virtual machine, most tools such as Ansible, Terraform, Graffana - - etc  were developed using Linux OS as the preferred OS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  End Goals
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Become a DevOps Engineer or SRE(Site Reliability Engineer)&lt;/li&gt;
&lt;li&gt;Understand the core concepts of cloud computing and infrastructure management.&lt;/li&gt;
&lt;li&gt;Earn cerification in any cloud computing platform.&lt;/li&gt;
&lt;li&gt;Gain hands on experience with monitoring tools, logging systems, version control systems, automation tools&lt;/li&gt;
&lt;li&gt;Learn a programming language:- Python, Java, Go, Rust, JavaScript. Although several languages can be used to learn DevOps, I will suggest - -  Python because of its simplicity, since it easy to pick-up and learn, readable syntax and it is the moost widely adopted language for DevOps - and SRE.&lt;/li&gt;
&lt;li&gt;Linux certification can also be acquired, although this is not necessary.&lt;/li&gt;
&lt;li&gt;Become a sought after DevOps Engineer and be job ready.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Learning Path
&lt;/h2&gt;

&lt;p&gt;**Note: This learning path is designed to provide a comprehensive understanding of the skills.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;DevOps Fundamentals&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=j5Zsa_eOXeY"&gt;VevOps for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=M988_fsOSWo"&gt;Cloud Computing Platforms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=POPP2WTJ8es"&gt;Infrastructure as a Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Version Control System&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=apGV9Kg7ics&amp;amp;list=PL9gnSGHSqcnoqBXdMwUTRod4Gi3eac2Ak&amp;amp;index=2&amp;amp;t=2s"&gt;Introduction to Github&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=qP8kir2GUgo&amp;amp;t=15s"&gt;Gitlab CI/CD Tutorial for Beginner&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://resources.github.com/devops/"&gt;Introduction to Github for DevOps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/course/gitlab-ci-pipelines-ci-cd-and-devops-for-beginners/"&gt;GitLab CI: Pipelines, CI/CD and DevOps for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Linux Fundamentals&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=sWbUDq4S6Y8"&gt;Introduction to Linux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://zerotomastery.io/courses/devops-bootcamp/"&gt;Linux and Linux SysAdmin for DevOps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/learn/linux-cloud-devops"&gt;Linux Cloud DevOps Course&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Python Programming Language&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=8DvywoWv6fI&amp;amp;t=40735s"&gt;Free Python Course&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/course/100-days-of-code/"&gt;Python Bootcam&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.python.org/"&gt;Python Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Shell and Bash Scripting&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/projects/introduction-to-bash-shell-scripting"&gt;Introduction to Bash - Shell Scripting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=tK9Oc6AEnR4"&gt;Bash scripting for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://devdocs.io/bash/"&gt;Bash - Shell Script for DevOps&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/course/linux-shell-scripting-projects/"&gt;Linux Shell Scripting: A Project-Based Approach to Learning&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Jenkins&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=FX322RVNGj4"&gt;Jenkins Tutorial For Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/course/jenkins-from-zero-to-hero/"&gt;Jenkins, From Zero To Hero: Become a DevOps Jenkins Master&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.jenkins.io/doc/book/"&gt;Jenkins User Guide and Implementation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Docker&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=pTFZFxd4hOI"&gt;Docker Tutorial for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/&amp;gt;%20%20%20%20%20projects/googlecl%20%20%20ud-introduction-to-docker-2zs0k"&gt;Google Cloud: Introduction to Docker Course&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.docker.com/?_gl=1*tulpnu*_ga*MTgzODUzOTQ3Mi4xNzA0OTcxNDU5*_ga_XJWPQMJYHQ*MTcwNDk3MTQ1OC4xLjEuMTcwNDk3MTYwOC42MC4wLjA."&gt;Docker docs and guides&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Kubernetes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=KVBON1lA9N8&amp;amp;t=14s"&gt;Kubernetes: Architecture Simplified&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/"&gt;Certified Kubernetes Administrator with Practise Tests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=kTp5xUtcalw"&gt;Docker Containers and Kubernetes&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Prometheus&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/playlist?list=PLVx1qovxj-anCTn6um3BDsoHnIr0O2tz3"&gt;Prometheus and Grafana&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=7gW5pSM6dlU"&gt;Monitoring with Prometheus And Grafana&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;TerraForm&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kodekloud.com/courses/terraform-for-beginners/"&gt;Terraform for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Ansible&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.ansible.com/overview/how-ansible-works"&gt;Ansible Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=EcnqJbxBcM0"&gt;Ansible Tutorial For Beginners&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Learning and Cloud Certification
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;AWS&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/certification/certified-cloud-practitioner/"&gt;AWS Cloud Practioner&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/learn/aws-cloud-practitioner-essentials?"&gt;Coursera Cloud Practitioner Certification&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;AZURE&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/learn/microsoft-azure-cloud-services?specialization=microsoft-azure-fundamentals-az-900"&gt;Introduction to Microsoft Azure Cloud Services&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Google Cloud&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/learn/certification/cloud-devops-engineer"&gt;Professional Cloud DevOps Engineer&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.coursera.org/learn/gcp-fundamentals?specialization=sre-devops-engineer-google-cloud"&gt;Google Cloud Fundamentals: Core Infrastructure&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Subscriptions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://zerotomastery.io/"&gt;Zero To Mastery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kodekloud.com/"&gt;KodeCloud&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Project
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.tutorialspoint.com/devops-projects-20-real-time-devops-projects/index.asp"&gt;TutorialsPoint&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Searching Algorithm in JS</title>
      <dc:creator>Olaide Emmanuel</dc:creator>
      <pubDate>Wed, 01 Nov 2023 06:46:52 +0000</pubDate>
      <link>https://dev.to/delaquash/searching-algorithm-in-js-47kg</link>
      <guid>https://dev.to/delaquash/searching-algorithm-in-js-47kg</guid>
      <description>&lt;p&gt;Search is literally a process we undertake everyday as humans, though with different method. We tend to search for a single toy in a pack of toys, books within a bookshelf, picture amongst frames.  Searching algorithms tends to check and retrieve an element from a list of element. &lt;br&gt;
We have 2 categories under Searching Algorithm :- &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linear Search&lt;/strong&gt;: This is a very important aspect of search algorithm, it simply loops over each element in an array, does not care if the array is sorted and stops if that element equals to the target value. In JS, array function such as &lt;strong&gt;find(), findIndex(), includes(),&lt;/strong&gt; &lt;strong&gt;indexOf()&lt;/strong&gt; uses linear search under the hood. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;/li&gt;
&lt;/ul&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%2Fqdrhu402fujg3gowafpo.gif" 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%2Fqdrhu402fujg3gowafpo.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Steps to perform a Linear Search
&lt;/h2&gt;

&lt;p&gt;Linear search takes in an unsorted array and also a target to search for.&lt;br&gt;
Starts checking from the first element in the array till it finds the target.&lt;br&gt;
If it finds the target, stops and then return the target index, if it doesn't it continues till it does and if the target cannot be found, then we return -1 as the return value from the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function linearSearch (arr: number[], target: number): number{
    for (let i in arr){
        if(arr[i] === target) return i
    }
    return -1
}

console.log(linearSearch([3, 6, 9, 12], 6)) // 0
console.log(linearSearch([2, 4, 6, 8], 9)) // -1
console.log(linearSearch([4, 8, 12, 16, 24], 24)) // 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Time and Space Complexity for Linear Search&lt;/em&gt;&lt;br&gt;
Now that we have understanding on how to perform linear search, we also have to determine the time and space complexity of our linear search function by looking at the best case, average case and worst case, and also space complexity of our code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Best Case Time Complexity of Linear Search&lt;/em&gt;&lt;br&gt;
If the targeted value is place at the beginning of the array list, the linear search function will only be perform a single comparison, irrespective of the number or size of the array. The runtime for this algorithm is a constant time of 0(1).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Average Case Time Complexity&lt;/em&gt;&lt;br&gt;
If the targeted value is placed at the mid of the array list, then the complexity will be 0(n/2) simplifying 0(n) or linear time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Worse Case Time Complexity&lt;/em&gt;&lt;br&gt;
When we discover that the targeted value is placed at the end of the array list, then we will have to perform n(length of input array) which makes our time complexity to be linear or 0(n).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Space Complexity of Linear Search&lt;/em&gt;&lt;br&gt;
Linear Search has a space complexity of O(1) – constant space.&lt;/p&gt;


&lt;h2&gt;
  
  
  Binary Search
&lt;/h2&gt;

&lt;p&gt;Unlike linear search method, binary search can only be used to search through ordered list or sorted arrays. Binary search utilizes the &lt;strong&gt;divide and conquer method&lt;/strong&gt; to search for an element by dividing the array into halves, and if the value is found returns the index of the element, if not, returns -1. It is specifically useful for large arrays that are sorted. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/tutorials/js-linear-vs-binary-search" rel="noopener noreferrer"&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%2Fxc0vyktg6ollqnorxaje.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Steps to perform a Binary Search.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We start counting the index of the element in the array starting at 0 and dividing by 2 to get the midValue.&lt;/p&gt;

&lt;p&gt;Using this midValue, we can then divide the element in the array in half( this is the divide and conquer method).&lt;/p&gt;

&lt;p&gt;If the midValue is greater than the target, our search will through the element at the right-hand-side and if lesser than the target, the search will at the left-hand-side because the target will surely be there.&lt;/p&gt;

&lt;p&gt;We therefore continue to repeat the process until we find the target.&lt;br&gt;
Example an array of numbers( not prime) with target of 13&lt;br&gt;
           [1, 3, 5, 7, 9, 11, 13, 17, 19, 23] &lt;br&gt;
Using this array starting at 1 with index 0, we have 0-9 index.&lt;br&gt;
So the midValue is index 4 which is 9, so we divide into this&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   [1,2,3,5,7,9] ---- LHS, [11,13,17,19,23] -----RHS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Since target is greater the LHS, we can sinply ignore it and focus of the RHS, then pick the midValue again which is 2( remember we count and divide by index)&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         [11, 13, 17] --- LHS, [19, 23] ---RHS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Since target is less than the first element in the RHS side array, we can discard the RHS array and focus on the LHS which has our target value at index 1.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;CodeXample&lt;/em&gt;&lt;br&gt;
We have a function that accepts an array of numbers and a target and returns 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;function binarySearch(arr: number[], target: number): number {
    let startValue : number = 0;
    let endValue : number = arr.length -1
    let midValue: number = Math.floor((startValue+endValue) /2)
    while (arr[midValue] !== target) {
        if(target &amp;lt; arr[midValue]){
            endValue = midValue - 1
        } else {
            startValue = midValue + 1
        }
        midValue = Math.floor((startValue+endValue) /2)
    }
    if(arr[midValue] === target){
        return midValue
    }
    return -1
}
console.log(binarySearch([2, 5, 6, 9, 13, 15, 28, 30], 9)) // 1
console.log(binarySearch([1, 2, 3, 4, 5], 5)) // 4
console.log(binarySearch([17, 18, 19, 20, 21, 22, 23],22)) // 5
console.log(binarySearch([17, 18, 19, 20, 21, 22, 23],16)) // -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Time and Space Complexity for Binary Search.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Best Case Time Complexity of Binary Search&lt;/em&gt;&lt;br&gt;
The best case complexity of Binary search occurs when the target value is located in the middle of array list. This illustrate that the result will be gotten in constant time irrespective of the size of the array, making the time complexity to be constant time or 0(1).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Average Case Time Complexity&lt;/strong&gt;&lt;br&gt;
Due to the fact that BS are always sorted unlike LS, the average case is also of O(log(n)).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Worse Case Time Complexity&lt;/strong&gt;&lt;br&gt;
The worst case complexity of Binary Search occurs when the target value is at the beginning or end of the array.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Space complexity of Binary Search&lt;/em&gt;&lt;br&gt;
Binary Search requires three pointers to elements (start, middle and end), regardless of the size of the array. Therefore the space complexity of Binary Search is O(1) or constant space.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>datastructures</category>
      <category>algorithms</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
