Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
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
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 MoreConstruct objects from joining two strings JavaScript
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 MoreJavaScript Total subarrays with Sum K
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 MoreCumulative sum at each index in JavaScript
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 MoreFinding minimum deletions in string in JavaScript
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 MoreFinding Sum of Left Leaves of a BST in JavaScript
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 MoreFinding number of open water taps after n chances using JavaScript
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 MoreHow to set the horizontal scale factor of Ellipse using FabricJS?
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 MoreHow to set the horizontal scale factor of Textbox using FabricJS?
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 MoreHow to convert an IText object into a data-like URL string using FabricJS?
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