πŸ“„Code Snippets

Browse 16 amazing code snippets from our community

React Custom Hook for API

<h3>πŸ”Ή Overview</h3><p>React custom hooks help separate <strong>data fetching logic</strong> from UI components, keeping them clean and reusable.</p><hr><h3>πŸ”Ή Concept</h3><p>Custom hooks are just normal JavaScript functions that use React’s built-in hooks (<code>useState</code>, <code>useEffect</code>) internally.</p><p>&nbsp;</p><p>&nbsp;</p>

javascript
#custom-hooks
πŸ‘€cs
πŸ“…12 Oct 2025

sorting in js

<p>Sorting means arranging elements in <strong>ascending or descending order</strong>.<br>We’ll implement a classic algorithm β€” <strong>Bubble Sort</strong> β€” for simplicity and understanding.</p><blockquote><p><strong>Idea:</strong> Repeatedly swap adjacent elements if they are in the wrong order.<br><strong>Time Complexity:</strong> O(nΒ²)<br><strong>Best For:</strong> Small datasets or learning basic sorting logic.</p></blockquote>

javascript
#javascript
πŸ‘€cs
πŸ“…10 Oct 2025

binary search js

<p>Binary Search is an efficient algorithm to find an element in a sorted array.<br>It works by repeatedly dividing the search interval in half:</p><p>Compare the target value to the middle element.</p><p>If they are equal β€” the search is successful.</p><p>If the target is smaller β€” continue searching in the left half.</p><p>If the target is larger β€” continue searching in the right half.</p><p>Time Complexity: O(log n)<br>Requirement: The array must be sorted.</p>

javascript
#algorithm#data-structures#recursion#search
πŸ‘€cs
πŸ“…14 Oct 2025

Hello World

<p>a simple <strong>β€œHello, World!”</strong> program in <strong>Python</strong></p>

python
#python
πŸ‘€cs
πŸ“…10 Oct 2025