Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 42 of 151

Subtract two Sets in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

Set subtraction (difference) removes all elements from the first set that exist in the second set. JavaScript doesn't provide a built-in difference method, but we can create one using forEach or modern Set methods. Using forEach Method We can create a static method to subtract one Set from another: Set.difference = function(s1, s2) { if (!(s1 instanceof Set) || !(s2 instanceof Set)) { console.log("The given objects are not of type Set"); return null; ...

Read More

The Set Class in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 191 Views

JavaScript's built-in Set class is a collection of unique values that allows you to store distinct elements of any type. Unlike arrays, Sets automatically prevent duplicate values and provide efficient methods for adding, removing, and checking element existence. Creating a Set You can create a Set using the new Set() constructor, optionally passing an iterable like an array: // Empty set let mySet = new Set(); // Set from array let numbersSet = new Set([1, 2, 3, 4, 4, 5]); console.log(numbersSet); // Duplicates are automatically removed let wordsSet = new Set(['hello', 'world', 'hello']); console.log(wordsSet); ...

Read More

Dictionary Data Structure in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection. Note that a dictionary is also known as a map. The dictionary problem is a classic computer science problem: the task of designing a data structure that maintains a set of data during 'search', 'delete', and 'insert' operations. There are many different types of implementations of dictionaries. Hash Table implementation Tree-Based Implementation (Self-balancing ...

Read More

Remove elements from a Dictionary using Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 25K+ Views

In JavaScript, there are multiple ways to remove elements from dictionary-like structures. This depends on whether you're working with plain objects, custom dictionary classes, or ES6 Maps. Using delete Operator with Objects For plain JavaScript objects acting as dictionaries, use the delete operator: const dict = { key1: "value1", key2: "value2", key3: "value3" }; console.log("Before deletion:", dict); delete dict.key2; console.log("After deletion:", dict); console.log("key2 exists:", "key2" in dict); Before deletion: { key1: 'value1', key2: 'value2', key3: 'value3' } After ...

Read More

The Keys and values method in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 300 Views

JavaScript provides several methods to extract keys and values from objects and Maps. The most common approaches are Object.keys(), Object.values() for plain objects, and the keys(), values() methods for ES6 Maps. Getting Keys from Objects Use Object.keys() to extract all property names from an object as an array: const myObject = { key1: "value1", key2: "value2", key3: "value3" }; const keys = Object.keys(myObject); console.log(keys); [ 'key1', 'key2', 'key3' ] Getting Values from Objects Object.values() extracts all property ...

Read More

The Dictionary Class in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 511 Views

JavaScript doesn't have a built-in Dictionary class, but we can create our own using objects or the Map class. Here's a complete implementation of a custom Dictionary class called MyMap. Complete Dictionary Implementation class MyMap { constructor() { this.container = {}; } display() { console.log(this.container); } hasKey(key) { return key in this.container; } ...

Read More

Hash Table Data Structure in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access to data becomes very fast if we know the index of the desired data. Thus, it becomes a data structure in which insertion and search operations are very fast irrespective of the size of the data. Hash Table uses an array as a storage medium and uses the hash technique to generate an index where an element is to be inserted or is to ...

Read More

Effects and animations with Google Maps markers in HTML5

Samual Sam
Samual Sam
Updated on 15-Mar-2026 310 Views

Google Maps API doesn't provide built-in fade or animation effects for standard markers. However, you can create custom animations by implementing Custom Overlays that give you full control over marker appearance and behavior. Why Custom Overlays? Standard Google Maps markers have limited animation options. Custom overlays allow you to: Control opacity and CSS transitions Create fade in/out effects Add custom animations using CSS or JavaScript Implement bounce, slide, or rotation effects Creating a Custom Overlay Class // Custom overlay class extending Google Maps OverlayView function CustomMarker(position, map, content) { ...

Read More

How to set the maximum width of an element with JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 2K+ Views

The maxWidth property in JavaScript allows you to set the maximum width of an element dynamically. This property controls how wide an element can grow, which is particularly useful for responsive layouts and content that needs width constraints. Syntax element.style.maxWidth = "value"; The value can be specified in pixels (px), percentages (%), em, rem, or other valid CSS units. Example: Setting Maximum Width #box { ...

Read More

WebGL: Prevent color buffer from being cleared in HTML5

Samual Sam
Samual Sam
Updated on 15-Mar-2026 236 Views

In WebGL, the color buffer is automatically cleared at the beginning of each frame by default. This can be problematic when you want to preserve previous drawings for effects like trails or persistent graphics. The Problem Even when you manually clear the color buffer using clearColor() and clear(), the WebGL context automatically clears the drawing buffer before the next frame: // Manual clearing - but buffer still gets cleared automatically gl.clearColor(0.0, 0.0, 0.0, 1.0); gl.clear(gl.COLOR_BUFFER_BIT); This automatic clearing happens at the beginning of the next draw cycle, making it impossible to build up graphics ...

Read More
Showing 411–420 of 1,507 articles
« Prev 1 40 41 42 43 44 151 Next »
Advertisements