Articles on Trending Technologies

Technical articles with clear explanations and examples

Replace all occurrence of specific words in a sentence based on an array of words in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 580 Views

We are required to write a JavaScript function that takes a string and an array of strings. Our function should return a new string, where all the occurrences of the word in the string that are present in the array are replaced by a whitespace. Our function should use the String.prototype.replace() method to solve this problem. Understanding the Problem When filtering words from a sentence, we need to: Match whole words only (not parts of words) Handle case-insensitive matching Use regular expressions ...

Read More

Construct objects from joining two strings JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 383 Views

We are required to write a JavaScript function that takes in two comma separated strings. The first string is the key string and the second string is the value string, the number of elements (commas) in both the strings will always be the same. Our function should construct an object based on the key and value strings and map the corresponding values to the keys. Example const str1= '[atty_hourly_rate], [paralegal_hourly_rate], [advanced_deposit]'; const str2 = '250, 150, 500'; const mapStrings = (str1 = '', str2 = '') => { const keys = ...

Read More

JavaScript Total subarrays with Sum K

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

In this problem, we need to find the total number of continuous subarrays within an array that have a sum equal to a given value K using JavaScript. Understanding the Problem Given an array of integers and a target sum K, we need to count all possible subarrays whose elements sum up to K. A subarray is a contiguous sequence of elements within an array. For example, if we have array [1, 2, 3, 4, 5] and K = 6, the subarrays with sum 6 are [1, 2, 3] and [2, 4], giving us a count of 2. ...

Read More

Cumulative sum at each index in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In JavaScript, calculating the cumulative sum (also known as running sum or prefix sum) at each index means computing the sum of all elements from the beginning of the array up to the current position. This is a common array operation used in algorithms and data analysis. What is Cumulative Sum? The cumulative sum is the calculation of the sum of a series of numbers up to a given index. Each element in the resulting array represents the sum of all previous elements including the current element. For example, given an array [1, 2, 3, 4, 5], ...

Read More

Finding minimum deletions in string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 230 Views

When working with binary strings, we often need to ensure no two adjacent characters are the same. This requires finding the minimum number of deletions to create an alternating pattern. Problem Statement Given a binary string, we need to find the minimum deletions required so that no two adjacent characters are identical. const str = '001001'; console.log("Original string:", str); Original string: 001001 For the string '001001', we need 2 deletions to get '0101' (removing characters at indices 0 and 3). Solution Approach The algorithm iterates through the string and ...

Read More

Finding Sum of Left Leaves of a BST in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 397 Views

We are required to write a JavaScript function that takes in the root of a Binary Search Tree as the only argument. The function should simply calculate the sum of data stored in the left leaves of the BST. Problem Example For example, if the Tree looks like this: 8 / \ 1 10 / \ 5 17 Then the output should be: 6 Output Explanation Because there are two left leaves in the ...

Read More

Finding number of open water taps after n chances using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 169 Views

Problem Suppose a school organises this game on their Annual Day celebration − There are "n" water taps and "n" students are chosen at random. The instructor asks the first student to go to every tap and open it. Then he has the second student go to every second tap and close it. The third goes to every third tap and, if it is closed, he opens it, and if it is open, he closes it. The fourth student does this to every fourth tap, and so on. After the process is completed with the "n"th student, how many taps ...

Read More

How to set the horizontal scale factor of Ellipse using FabricJS?

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

In this tutorial, we are going to learn how to set the horizontal scale factor of an Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will have to create an instance of fabric.Ellipse class and add it to the canvas. Just as we can specify the position, color, opacity and dimension of an ellipse object in the canvas, we can also set the horizontal scale of an ellipse object. This can be done by using the scaleX property. Syntax new fabric.Ellipse({ scaleX : Number }: ...

Read More

How to set the horizontal scale factor of Textbox using FabricJS?

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

In this tutorial, we are going to learn how to set the horizontal scale factor of a Textbox using FabricJS. We can customize, stretch or move around the text written in a textbox. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. Just as we can specify the position, colour, opacity and dimension of a textbox object in the canvas, we can also set the horizontal scale factor of a textbox object. This can be done by using the scaleX property. Syntax new fabric.Textbox(text: ...

Read More

How to convert an IText object into a data-like URL string using FabricJS?

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

In this tutorial, we are going to learn about how to convert an IText object into a data-like URL string using FabricJS. The IText class was introduced in FabricJS version 1.4, extends fabric.Text and is used to create IText instances. An IText instance gives us the freedom to select, cut, paste or add new text without additional configurations. There are also various supported key combinations and mouse/touch combinations which make text interactive which are not provided in Text. Textbox, however, which is based on IText allows us to resize the text rectangle and wraps lines automatically. This is not ...

Read More
Showing 15071–15080 of 61,297 articles
Advertisements