Articles on Trending Technologies

Technical articles with clear explanations and examples

Validating a power JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 253 Views

In JavaScript, validating whether a number is a power of another number (like 3) is a common programming problem. We need to check if a given number can be expressed as nk where n is our base and k is a non-negative integer. To solve this validation, we use arithmetic operators like modulus (%), division (/), and comparison operators. The key insight is that powers of a number can only be divided by that base number repeatedly until we reach 1. Understanding the Problem Let's look at some examples to understand when a number is a power ...

Read More

Function for counting frequency of space separated elements in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 359 Views

In this problem statement, our target is to create a function for counting frequency of space separated elements with the help of JavaScript functionalities. Understanding the Problem The given problem is stating that we have given a space separated elements and our task is to count the frequency of space separated items. So we will provide some strings with some space separated items and assign a result array to see the counts of the frequency of such items. For example if we have a string with space separated items like "Car Bike Car Bicycle Bike", in this example ...

Read More

Finding two prime numbers with a specific number gap in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 292 Views

Finding prime numbers with a specific gap is a common programming challenge. This involves identifying two prime numbers where their difference equals a given value within a specified range. Problem We need to write a JavaScript function that takes a gap number and a range array as arguments. The function should return the first pair of prime numbers that have an absolute difference equal to the gap and fall within the specified range. Algorithm Approach The solution involves two main steps: Find all prime numbers within the given range Search for consecutive primes with the specified gap ...

Read More

Counting matching substrings in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 261 Views

Counting matching substrings in JavaScript is essential for text analysis and string manipulation tasks. This article explores different methods to count subsequences within a string, helping developers choose the most appropriate approach for their needs. Problem Statement We need a JavaScript function that counts subsequences in a given string. The function takes a string "str" and an array of strings "arr" as input. It examines each element in "arr" and determines how many strings are subsequences of "str". A subsequence is formed by removing characters from the original string while maintaining the relative order of remaining characters. ...

Read More

How to set the opacity of a Circle using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 412 Views

In this tutorial, we are going to learn how to set the opacity of Circle using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will create an instance of fabric.Circle class and add it to the canvas. We can customize a circle object by adding a fill colour to it, eliminate its borders or even make changes in its dimensions. Similarly, we can also change its opacity by using the opacity property. Syntax new fabric.Circle({ opacity: Number }) Parameters ...

Read More

FabricJS – How to move a Line object one step down in the stack of drawn objects?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 399 Views

In this tutorial, we are going to learn about how to move a Line object one step down in the stack of drawn objects using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to move a Line object one step down in the ...

Read More

How to prevent sticky hover effects for buttons on touch devices?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 2K+ Views

Touch devices often exhibit "sticky" hover effects where buttons remain in their hovered state after being tapped. This creates a poor user experience as the visual feedback doesn't match the intended interaction model of touch interfaces. The Problem with Hover on Touch Devices Touch screens don't have true hover capabilities, but many browsers simulate hover events when elements are touched. This causes several issues: Elements may remain in their hovered state after being tapped, creating a "sticky" effect On iOS devices, the hover state briefly appears before navigation, causing visual flicker Hover effects that show/hide elements ...

Read More

FabricJS – How to check if a Polygon Object Intersects with Another Object?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 998 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to check if a Polygon object intersects with another object, we use the intersectsWithObject method. This method checks whether the object that is passed to it, intersects with the polygon object. Syntax intersectsWithObject(other: Object, absolute: Boolean, calculate: Boolean ): Boolean ...

Read More

How to create a dynamic length array with numbers and sum the numbers using JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

In JavaScript, arrays are always dynamic in length. Unlike some programming languages, we don't need to define the array's length while creating it. We can create an array and push whatever number of elements we want. Here, we will create a dynamic length array with numbers and sum all its elements. Using For Loop to Sum Array Elements We can iterate over the array using a for loop and add every element to get the sum. Let's look at both traditional for loops and for-of loops. Syntax let arraySum = 0; for (let i = ...

Read More

Merging sorted arrays together JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 982 Views

Merging two sorted arrays in JavaScript involves combining them into a single sorted array. This is a common problem in data structures and algorithms that uses the greedy approach to efficiently merge pre-sorted arrays. What are Sorted Arrays? Sorted arrays are arrays where elements are arranged in a specific order, typically ascending. In JavaScript, arrays are resizable collections that can be sorted using the built-in sort() method. // Array before sorting var arr = [2, 5, 1, 3, 6, 9, 7]; console.log("Before sorting:", arr); ...

Read More
Showing 15371–15380 of 61,297 articles
Advertisements