Snippets
Factory Function Pattern in Javascript
Factory functions are a powerful design pattern in JavaScript for creating objects. Unlike constructor functions that require the new keyword, factory functions are regular functions that return a new object when called.
Sep 24, 2024
Find the maximum Depth of a Binary Tree
Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
Sep 21, 2024
Find the Duplicate in a sequence of 1 to n with size n+1
This problem focuses on the series formula for getting the sum of the series of length n and then finding the duplicate by using that sum as refernce
Sep 12, 2024
document.createDocumentFragment for Batch DOM updates
The DocumentFragment is an interface that represents a temporary container for holding a group of DOM nodes. It acts like a mini-document but is not part of the actual DOM tree. This allows developers to construct and manipulate multiple nodes or elements in memory without immediately adding them to the visible DOM. The main performance advantage of using DocumentFragment is that it avoids triggering reflows and repaints during the construction phase. By batching multiple DOM operations and appending them all at once, you significantly reduce the overhead caused by repeated DOM mutations, which can be costly in terms of performance, especially with large or frequent updates.
Sep 11, 2024
Compound Components in React
Compound components in React offer a powerful design pattern for creating flexible and reusable UI elements, allowing multiple components to work together as a cohesive unit while maintaining a clean API - a simple example is a Tabs component that manages its own state and renders child Tab components based on user interaction, enabling encapsulation, flexibility, and readability in your React applications.
Sep 9, 2024
Simple Debounce Implementation in Javascript
This is a simple implementation of Debounce Function Wrapper that helps you debounce functions which are called multiple times in a short interval.
Sep 7, 2024
Check my latest Blog Post