Articles on Trending Technologies

Technical articles with clear explanations and examples

Finding the longest common consecutive substring between two strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We are required to write a JavaScript function that takes in two strings. Let's call them str1 and str2. The function should then find out the longest consecutive string that is common to both the input strings and return that common string. For example − If the input strings are − const str1 = 'ABABC'; const str2 = 'BABCA'; Then the output string should be − const output = 'BABC'; How It Works This problem uses dynamic programming to build a 2D matrix where each cell [i][j] represents the ...

Read More

Adding elements to array to make its sum diverse in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 224 Views

We are required to write a JavaScript function that takes in an array of Numbers, arr, as the first argument and a single number, num, as the second argument. We should, by adding elements to it, make our array such that any sum can be obtained by adding specific numbers from it between [0, num] (including both). Our function should finally return the minimum number of numbers required to add to the array so that it can produce any sum between 0 and num. Problem Example For example, if the input to the function is: ...

Read More

Counting the number of letters that occupy their positions in the alphabets for array of strings using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 403 Views

We are required to write a JavaScript function that takes in an array of strings of English lowercase alphabets. Our function should map the input array to an array whose corresponding elements are the count of the number of characters that had the same 1-based index in the string as their 1-based index in the alphabets. For instance, this count for the string 'akcle' will be 3 because the characters 'a', 'c' and 'e' have 1-based index of 1, 3 and 5 respectively both in the string and the English alphabets. Understanding the Problem We need ...

Read More

JavaScript: How to map array values without using \"map\" method?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 2K+ Views

When you need to transform array elements without using the built-in map() method, JavaScript provides several alternatives. These approaches manually iterate through arrays and apply transformations to create new arrays with modified values. Table of Contents You can map array values without using the map method in the following ways: Using forEach() Using reduce() Using a for Loop Using while Loop Using forEach() The forEach() method iterates through each array element, allowing you to apply transformations while manually building a ...

Read More

How to create a Rectangle with not-allowed cursor on hover over objects using FabricJS?

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

In this tutorial, we are going to create a Rectangle with a not-allowed cursor on hover over objects using FabricJS. not-allowed is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., that actually reuse the native cursor under the hood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Rect({ hoverCursor: String }: Object) Parameters ...

Read More

Voca: The Ultimate Javascript library for String Manipulation

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

Voca is a powerful JavaScript library designed specifically for string manipulation. In this tutorial, we will explore multiple examples demonstrating how to use the different functions available in Voca. Features of Voca Before we see all the examples, let's highlight some features that Voca brings to the table − It provides a multitude of functions that can be used to manipulate, query, escape, format strings. It also provides detailed and searchable documentation. It supports a wide range of environments like Node.js, Safari 7+, Chrome, ...

Read More

How to lock the vertical movement of Line using FabricJS?

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

In this tutorial, we are going to learn how to lock the vertical movement of Line 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. We can also specify whether we want line object to move only in the X-axis. This can be done by ...

Read More

Substitute random items in a JavaScript array?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 514 Views

To substitute random items in a JavaScript array, you can use Math.random() along with map() to replace selected elements with new values while keeping others in their original positions. For example, if you have an array [m, n, o, p] and want to replace two random items with 'a', the result might be [a, a, o, p] where m and n were randomly selected and replaced. Using Math.random() Method The Math.random() method returns a pseudo-random number between 0 (inclusive) and 1 (exclusive). It's used to generate random indices for array element selection. Syntax Math.random(); ...

Read More

How to process JavaScript nested array and display the order of numbers according to the level upto which they are nested?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 360 Views

Processing nested arrays and displaying elements with proper indentation based on their nesting level is a common JavaScript task. This technique helps visualize the hierarchical structure of nested data. Problem Statement Given a nested array like this: const arr = [23, 6, [2, [6, 2, 1, 2], 2], 5, 2]; We need to display numbers with indentation showing their nesting level. Elements at deeper levels should have more indentation. Expected Output 23 6 2 6 2 ...

Read More

Longest path in 2-D that contains increasing sequence in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 449 Views

In JavaScript, finding the longest path in a 2-D array that contains an increasing sequence is a classic dynamic programming problem that can be solved efficiently using memoized depth-first search. Increasing Sequence A sequence of numbers in which each succeeding element is greater than the preceding element forms an increasing sequence. For instance: 4, 6, 8, 9, 11, 14 is an increasing sequence 1, 2, 3, 4, 5 is also an increasing sequence Problem Statement We need to write a JavaScript function that takes a 2-D array of numbers and returns the ...

Read More
Showing 16041–16050 of 61,298 articles
Advertisements