Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Sai Subramanyam
67 articles
How to set the width of an element's border with JavaScript?
To set the width of an element's border in JavaScript, use the borderWidth property. This property allows you to dynamically modify border thickness after the page loads. Syntax element.style.borderWidth = "value"; The value can be specified in pixels (px), keywords (thin, medium, thick), or other CSS units. Example: Changing Border Width #box { border: thick solid gray; ...
Read MoreHow to set outline color with JavaScript?
To set outline color in JavaScript, use the outlineColor property. The outline appears outside an element's border and doesn't affect the element's dimensions or layout. Syntax element.style.outlineColor = "color"; Parameters The outlineColor property accepts any valid CSS color value: Color names: "red", "blue", "green" Hex values: "#FF5733", "#000000" RGB values: "rgb(255, 87, 51)" HSL values: "hsl(9, 100%, 60%)" Example: Setting Outline Color #box { ...
Read MoreHow to set the maximum height of an element with JavaScript?
Use the maxHeight property in JavaScript to set the maximum height of an element. This property controls how tall an element can grow, with content overflowing when the limit is reached. Syntax element.style.maxHeight = "value"; Parameters The maxHeight property accepts various values: Pixels: "200px" Percentage: "50%" (relative to parent) Keywords: "none" (no limit), "initial", "inherit" Example: Setting Maximum Height #box { width: 300px; background-color: gray; ...
Read MoreSearch Element in an Javascript Hash Table
JavaScript hash tables use a get method to search for elements by their key. The method calculates the hash code and searches through the chain at that index to find the matching key-value pair. The get() Method Implementation The search operation involves computing the hash code for the given key and then iterating through the chain at that bucket to find the exact match: get(key) { let hashCode = hash(key); for(let i = 0; i < this.container[hashCode].length; i ++) { ...
Read MoreLoop through a hash table using Javascript
Hash tables (also called hash maps) store key-value pairs and provide efficient lookup. To iterate through all entries, we need to traverse each chain in the underlying storage container since hash tables typically use chaining to handle collisions. Creating a forEach Method The forEach method loops over all key-value pairs in the hash table and executes a callback function for each pair. We iterate through each chain in the container and process every key-value pair. forEach(callback) { // For each chain in the hash table this.container.forEach(elem => { ...
Read MoreThe HashTable Class in Javascript
A HashTable (Hash Map) is a data structure that stores key-value pairs using a hash function to compute array indices. This implementation uses chaining to handle collisions, where multiple values can be stored at the same index using arrays. Complete HashTable Implementation class HashTable { constructor() { this.container = []; // Populate the container with empty arrays // which can be used to add more elements in // cases of collisions for (let i = ...
Read MoreBinary Tree in Javascript
Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children. A binary tree has the benefits of both an ordered array and a linked list as search is as quick as in a sorted array and insertion or deletion operation are as fast as in the linked list. Here is an illustration of a binary tree with some terms that we've discussed below: A Root ...
Read MoreHow to offset an outline and draw it beyond the border edge with JavaScript?
To offset an outline in JavaScript, use the outlineOffset property. This CSS property allows you to draw the outline beyond the border edge, creating space between the element's border and its outline. Syntax element.style.outlineOffset = "value"; The value can be specified in pixels (px), ems (em), or other CSS length units. Positive values move the outline away from the border, while negative values move it inward. Example #box { ...
Read MoreNode in Javascript
In JavaScript tree data structures, a node is the fundamental building block that contains data and references to other connected nodes. For binary trees, each node has three essential properties: the data it stores and references to its left and right child nodes. Node Structure A typical tree node contains the following components: data − Stores the actual value or information in the node left − Reference to the left child node right − Reference to the right child node Creating a Node Class ...
Read MoreInserting a key into a tree in Javascript
In a Binary Search Tree (BST), inserting a new key follows a simple rule: smaller values go to the left subtree, and larger values go to the right subtree. The first insertion creates the root node, while subsequent insertions traverse the tree to find the correct position. How BST Insertion Works The insertion process starts at the root and compares the new value with each node. If the value is smaller, we move left; if larger, we move right. When we reach a null position (leaf node), we insert the new node there. Binary ...
Read More