karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 38 of 143

Loop through a Set using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 701 Views

In JavaScript, you can loop through a Set using several methods. The most common approaches are using the forEach() method, for...of loop, or converting to an array. Using forEach() Method The forEach() method executes a provided function for each value in the Set: const mySet = new Set([1, 2, 5, 8]); mySet.forEach(value => { console.log(`Element is ${value}`); }); Element is 1 Element is 2 Element is 5 Element is 8 Using for...of Loop The for...of loop provides a cleaner syntax for iterating over Set values: ...

Read More

How to set the bottom margin of an element with JavaScript?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 805 Views

The marginBottom property in JavaScript allows you to dynamically set the bottom margin of an element. This property is part of the element's style object and accepts values in pixels, percentages, or other CSS units. Syntax element.style.marginBottom = "value"; Where value can be in pixels (px), percentages (%), em units, or other valid CSS margin values. Example: Setting Bottom Margin Here's how to set the bottom margin of an element when a button is clicked: ...

Read More

Creating a hash table using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 466 Views

A hash table (also called hash map) is a data structure that stores key-value pairs and provides fast lookup, insertion, and deletion operations. In JavaScript, we can implement a hash table using arrays and a hash function to map keys to array indices. Basic Hash Table Structure Let's create a hash table class with collision resolution using chaining. We'll use an array of arrays where each index can hold multiple key-value pairs in case of hash collisions. class HashTable { constructor() { this.container = ...

Read More

Add elements to a hash table using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 1K+ Views

When adding elements to a hash table, the most crucial part is collision resolution. We're going to use chaining for the same. There are other algorithms you can read about here: https://en.wikipedia.org/wiki/Hash_table#Collision_resolution Now let's look at the implementation. We'll be creating a hash function that'll work on integers only to keep this simple. But a more complex algorithm can be used to hash every object. Hash Table Implementation First, let's create a complete hash table class with the necessary components: class HashTable { constructor(size = 11) { ...

Read More

Remove elements from Javascript Hash Table

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 1K+ Views

To remove elements from a JavaScript hash table, we need to locate the element using its key and remove it from the underlying storage structure. In hash tables that use chaining for collision resolution, this involves searching through the chain at the computed hash index. Let us look at the implementation of the remove method: Remove Method Implementation remove(key) { let hashCode = this.hash(key); for (let i = 0; i < this.container[hashCode].length; i++) { // Find the element in ...

Read More

Joining two hash tables in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 662 Views

Sometimes we need to combine hash tables together using a join function to create a new merged hash table. We'll write a static join method that takes 2 HashTables and creates a new HashTable with all the values. For simplicity, values from the second hash table will override values from the first one if there are duplicate keys. Syntax static join(table1, table2) { // Implementation logic return newHashTable; } Implementation Here's the complete implementation of the join method: class HashTable { ...

Read More

Tree Data Structure in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 617 Views

The tree data structure represents hierarchical relationships like organization charts, file systems, and DOM elements. A tree consists of nodes connected in a parent-child relationship, where each node has a value and references to its children, with no duplicate references. Tree Terminology Understanding key tree terms is essential: Root: The top node with no parent Parent: A node that has children Child: A node connected to a parent above it Leaf: A node with no children Height: Maximum depth from root to any leaf Depth: Number of edges from root to a specific node ...

Read More

Binary Search Tree in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 486 Views

A Binary Search Tree (BST) is a specialized data structure where each node follows a specific ordering rule. A node's left child must have a value less than its parent's value, and the node's right child must have a value greater than its parent's value. 8 3 10 1 6 14 ...

Read More

Circle Collision Detection HTML5 Canvas

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 633 Views

Circle collision detection in HTML5 Canvas involves checking whether two circles intersect by calculating the distance between their centers and comparing it to the sum of their radii. How Circle Collision Detection Works Two circles collide when the distance between their centers is less than or equal to the sum of their radii. If the distance is greater, they don't collide. distance r1 r2 Basic Formula The collision detection formula uses the Pythagorean theorem to calculate distance: distance = Math.sqrt((x2 - x1)² + (y2 - y1)²) collision = distance

Read More

Creating a BinaryTree using Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 314 Views

A Binary Search Tree (BST) is a hierarchical data structure where each node has at most two children. Let's learn how to create and represent a binary search tree in JavaScript by building a complete BST class with essential operations. Basic Structure We'll start by creating the BinarySearchTree class and defining a Node class for individual tree elements. class BinarySearchTree { constructor() { // Initialize a root element to null this.root = null; ...

Read More
Showing 371–380 of 1,421 articles
« Prev 1 36 37 38 39 40 143 Next »
Advertisements