Articles on Trending Technologies

Technical articles with clear explanations and examples

Calculating quarterly and yearly average through JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 329 Views

In this tutorial, we'll learn how to calculate quarterly and yearly averages from an array of numbers using JavaScript. This involves chunking data into groups and computing their averages. Suppose we have an array of numbers like this: const arr = [1, 2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; console.log("Original array:", arr); Original array: [1, 2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] We need to group this array ...

Read More

How to replace elements in array with elements of another array in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 7K+ Views

In JavaScript, there are several ways to replace elements in one array with elements from another array. The most common approach uses the splice() method to modify the original array in place. Input-Output Scenarios Let's look at some common scenarios for replacing array elements: Array1 = [1, 3, 5, 7, 2, 4]; Array2 = [3, 6]; // Replace first 2 elements of Array1 with Array2 Output = [3, 6, 5, 7, 2, 4] Array1 = [3, 6]; Array2 = [1, 3, 5, 7, 2, 4]; // Replace all elements of Array1 with Array2 ...

Read More

Filtering array within a limit JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 795 Views

We are required to write a JavaScript function that takes in an array of numbers as the first argument and an upper limit and lower limit number as second and third argument respectively. Our function should filter the array and return a new array that contains elements between the range specified by the upper and lower limit (including the limits). Syntax const filterByLimits = (arr, upper, lower) => { return arr.filter(element => element >= lower && element { let res = []; res = arr.filter(el => { return el >= lower && el { return arr.filter(element => element >= lower && element = lower && element

Read More

Reversing array without changing the position of certain elements JavaScript

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

In this problem, we need to reverse an array while keeping certain elements in their original positions. This requires tracking preserved element positions and carefully swapping only the non-preserved elements. Understanding the Problem The goal is to reverse an array but preserve specific elements at their original positions. For example, if we have array [1, 2, 3, 4, 5, 6] and want to preserve elements [2, 4, 6], the result should be [5, 2, 3, 4, 1, 6] instead of a complete reversal. Algorithm Approach The solution involves: Track indices of elements to preserve Create ...

Read More

Factorize a number in JavaScript

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

In JavaScript, factorizing a number means finding all the prime factors that multiply together to form the original number. This is a fundamental mathematical operation used in cryptography, number theory, and various algorithms. Understanding Prime Factorization Prime factorization breaks down a number into its basic building blocks - prime numbers. For example, 36 = 2 × 2 × 3 × 3, where 2 and 3 are prime factors. We need to find all prime numbers that divide the given number without leaving a remainder. Algorithm Approach The efficient approach iterates from 2 to the square root ...

Read More

Calculating the weight of a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 967 Views

In JavaScript, calculating the weight of a string means finding the sum of alphabetical positions of all characters. Each letter's weight is its position in the alphabet (a=1, b=2, c=3, etc.). Understanding Character Weight The weight of an English alphabet character is its 1-based index position: 'a' has weight 1 'b' has weight 2 'c' has weight 3 'z' has weight 26 Method 1: Using indexOf() This approach uses a reference string to find each character's position: const str = 'this is a string'; const calculateWeight = (str = '') ...

Read More

Deleting desired node from a Binary Search Tree in JavaScrip

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 337 Views

Deleting a node from a Binary Search Tree is more complex than insertion because we need to handle three different cases depending on the node's children. This operation maintains the BST property where left children are smaller and right children are larger. Problem We have a Binary Search Tree implementation with insertion functionality. We need to add a deleteNode() function that removes a node with a specific value while maintaining the BST structure. class Node { constructor(data) { this.data = data; ...

Read More

Moving all vowels to the end of string using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 404 Views

In JavaScript, you can move all vowels to the end of a string while maintaining the relative positions of consonants. This is useful for text processing and string manipulation tasks. Problem We need to write a JavaScript function that takes a string and constructs a new string where all consonants maintain their relative positions and all vowels are moved to the end. Approach The solution involves iterating through the string, separating vowels and consonants into different variables, then concatenating them with consonants first and vowels at the end. Example const str = 'sample ...

Read More

Finding middlemost node of a linked list in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 213 Views

In JavaScript, finding the middle node of a linked list is a common problem that can be efficiently solved using the two-pointer technique, also known as the "tortoise and hare" algorithm. Problem Statement We need to write a JavaScript function that takes the head of a linked list and returns the value of the middlemost node. If there are two middle nodes (even number of nodes), we return the second one. For example, given the list: [4, 6, 8, 9, 1], the middle node contains the value 8. Two-Pointer Approach The most efficient solution uses ...

Read More

How to lock the flipping during scaling of Circle using FabricJS?

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

In this tutorial, we are going to learn how to lock the flipping during scaling of a Circle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a circle object in the canvas, we can also stop flipping of an object during scaling. This can be done by using the lockScalingFlip property. Syntax new fabric.Circle({ lockScalingFlip : Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional customizations to our ...

Read More
Showing 15041–15050 of 61,297 articles
Advertisements