Articles on Trending Technologies

Technical articles with clear explanations and examples

JavaScript Program To Delete Nodes Which Have A Greater Value On Right Side

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 375 Views

We will implement a function to delete nodes in a linked list which have a greater value on their right side. The approach is to traverse the linked list from right to left and keep track of the maximum value encountered so far. For each node, we compare its value with the maximum value and delete the node if its value is less than the maximum value. Problem Understanding Given a singly linked list, we need to delete all nodes that have at least one node with a greater value to their right. For example, in the list ...

Read More

How to concatenate regex literals in JavaScript?

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

Regular expressions (regex literals) are patterns used to match character combinations in strings. Sometimes, you need to combine multiple regex patterns into a single expression. Unlike strings, regex literals cannot be concatenated directly with the '+' operator. To concatenate regex literals, you must extract their source patterns and flags, combine them properly, and create a new RegExp object. Syntax Follow this approach to concatenate regex literals: let allFlags = regex1.flags + regex2.flags; let uniqueFlags = [...new Set(allFlags.split(''))].join(''); let combined = new RegExp(regex1.source + regex2.source, uniqueFlags); This extracts the source patterns and flags from ...

Read More

JavaScript Program to Efficiently Compute Sums of Diagonals of a Matrix

Ravi Ranjan
Ravi Ranjan
Updated on 15-Mar-2026 572 Views

In a square matrix, there are two main diagonals: the primary diagonal (left-to-right) and the secondary diagonal (right-to-left). Computing their sums efficiently is a common programming task with practical applications in linear algebra and image processing. In this article, we will explore two JavaScript approaches to calculate diagonal sums: a brute force method using nested loops and an optimized single-loop solution. 3x3 Matrix Diagonals ...

Read More

Find the OR and AND of Array elements using JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 201 Views

In JavaScript, we can use the '&&' operator to perform the AND operation between two elements and the '||' operator to perform OR operation between two elements. Here, we will learn to perform OR and AND operations between every element of the array using different approaches. Use the for Loop We can use the for loop to iterate through the array elements and perform OR or AND operations with all array elements. Syntax Users can follow the syntax below to use the for loop to take OR or AND operation of every element. ...

Read More

Parallel Programming in JavaScript with Web Workers and SIMD.js

Mukul Latiyan
Mukul Latiyan
Updated on 15-Mar-2026 822 Views

JavaScript traditionally executes tasks in a single-threaded manner, which can limit performance for computationally intensive operations. However, modern web technologies enable parallel programming through Web Workers and SIMD.js, allowing developers to leverage multi-core processors for improved efficiency. Understanding Parallel Programming Parallel programming involves dividing tasks into smaller subtasks that execute concurrently, utilizing multiple resources to improve performance. In JavaScript, this is particularly beneficial for complex computations, data processing, and simulations without blocking the main UI thread. Web Workers Web Workers enable JavaScript code execution in separate background threads, providing true parallel processing. They operate independently from ...

Read More

Finding the time elapsed in JavaScript

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

Finding time elapsed in JavaScript is essential for performance monitoring, measuring execution time, and tracking user interactions. JavaScript provides several built-in methods to calculate time differences accurately. In this tutorial, we'll explore three different approaches: the Date() object for general time calculations, console.time() for debugging, and performance.now() for high-precision measurements. Using the Date() Object The Date() constructor returns the current timestamp in milliseconds since January 1, 1970 (Unix epoch). We can calculate elapsed time by finding the difference between two timestamps. Syntax let startTime = new Date(); let endTime = new Date(); let timeElapsed ...

Read More

JavaScript Program for the Last duplicate element in a Sorted Array

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 512 Views

In this article, we are going to explore a JavaScript program that works with a sorted array containing duplicate elements. The task is to traverse the array using a loop and identify both the index of the last duplicate element and the duplicate number. Introduction to Problem In the given problem we have to find the last duplicate element in a sorted array. Duplicate means the number is present more than one time. Example − Input arr[] = {1, 2, 2, 3, 5, 5, 6, 7} Output Last index: 5 Last duplicate ...

Read More

How to find average color of an image using JavaScript?

Aman Gupta
Aman Gupta
Updated on 15-Mar-2026 1K+ Views

Finding the average color of an image involves extracting pixel data from the image and calculating the mean RGB values. JavaScript's Canvas API provides the tools needed to access and analyze image pixel data. How It Works The process involves drawing an image onto a canvas element, extracting pixel data using getImageData(), and calculating the average of all red, green, and blue values. The canvas element allows us to manipulate image data at the pixel level. Basic Syntax const canvas = document.createElement("canvas"); const context = canvas.getContext("2d"); context.drawImage(imageElement, 0, 0); const imageData = context.getImageData(0, 0, width, ...

Read More

JavaScript Program to Find a triplet such that sum of two equals to third element

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 385 Views

We will be writing a JavaScript program that finds a triplet where the sum of two elements equals the third element. This program will be implemented using arrays and loop structures. We will iterate through the array and check for each combination of three elements if two elements sum up to the third. If we find such a triplet, we will return it immediately. Problem Understanding Given an array, we need to find three elements (a triplet) where a + b = c. For example, in array [1, 4, 45, 6, 10, 8], the triplet [4, 6, 10] ...

Read More

JavaScript Program for the Least Frequent Element in an Array

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 785 Views

In this program, we are given an array of integers and need to return the element that appears the least number of times. If multiple elements have the same minimum frequency, we can return any one of them. Problem Statement Given an array with duplicate numbers, we need to count the occurrence of each element and return the one with the least frequency. If multiple elements have the same minimum frequency, any one can be returned. Example 1: Input: [1, 3, 3, 5, 5, 4, 4, 4] Output: 1 Explanation: 1 appears 1 time, 3 ...

Read More
Showing 14301–14310 of 61,297 articles
Advertisements