Articles on Trending Technologies

Technical articles with clear explanations and examples

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 360 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 198 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 556 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 306 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 469 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 324 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 382 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

Isosceles triangles with nearest perimeter using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 262 Views

Almost Isosceles Triangle An Almost Isosceles Integer Triangle is a triangle where all side lengths are integers and two sides are almost equal, with their absolute difference being exactly 1 unit of length. Problem Statement We need to write a JavaScript function that takes a number representing the desired perimeter of a triangle. The function should find an almost isosceles triangle whose perimeter is nearest to the input perimeter. For example, if the desired perimeter is 500, the almost isosceles triangle with the nearest perimeter will be [167, 166, 167] with perimeter 500. Understanding Almost ...

Read More

Finding the only out of sequence number from an array using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 515 Views

Problem We are required to write a JavaScript function that takes in an array of numbers. The array is sorted in ascending order and only one element in the array is out of order. Our function should find and return that element. Approach The solution works by checking each element against its neighbors. When we find an element that is greater than the next element AND the next element is also greater than the element after it, we've found our out-of-sequence number. Example Following is the code: const arr = [1, 2, 3, 4, 17, 5, ...

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