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
Finding three elements with required sum in an array in JavaScript
We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should then pick three such numbers from the array, (if they exist) whose sum is equal to the number specified by the second argument. The function should finally return an array of arrays of all such triplets if they exist, an empty array otherwise. For example − If the input array and the number is − const arr = [2, 5, 7, 8, 9, 11, 1, ...
Read MoreSmallest number after removing n digits in JavaScript
We need to write a JavaScript function that removes n digits from a number to make it as small as possible. This is a classic greedy algorithm problem that uses a stack-based approach. Problem Statement Given a number string m and an integer n, remove n digits from m to create the smallest possible number. For example: Input: m = '45456757', n = 3 Output: '44557' We remove digits 5, 6, and 7 to get the smallest result. Algorithm Approach We use a greedy algorithm with a stack: Process ...
Read MoreSum of individual even and odd digits in a string number using JavaScript
We are required to write a JavaScript function that takes in a string containing digits and our function should return true if the sum of even digits is greater than that of odd digits, false otherwise. Problem Statement Given a string of digits, we need to: Separate even and odd digits Calculate the sum of even digits Calculate the sum of odd digits Compare which sum is greater Example Let's implement a solution that processes each digit and compares the sums: ...
Read MoreChecking if change can be provided in JavaScript
We need to write a JavaScript function that determines whether a shopkeeper can provide exact change to all customers. The shopkeeper starts with no money and sells items costing ₹5, with customers paying using ₹5, ₹10, or ₹20 notes. Problem A shopkeeper sells a single commodity which costs exactly ₹5. Customers in a queue will purchase one unit each, paying with ₹5, ₹10, or ₹20 notes. The shopkeeper starts with no money and must provide exact change to each customer. The function should return true if all customers can receive proper change, false otherwise. Change Requirements ...
Read MoreHow to set the minimum allowed scale value of an Ellipse using FabricJS?
In this tutorial, we are going to learn how to set the minimum allowed scale of Ellipse using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we will create an instance of fabric.Ellipse class and add it to the canvas. We can customize an ellipse object by adding a fill color to it, eliminate its borders or even make changes in its dimensions. Similarly, we can also set its minimum allowed scale by using the minScaleLimit property. Syntax new fabric.Ellipse({ minScaleLimit : Number }: Object) Parameters ...
Read MoreHow to set the minimum allowed scale value of Textbox using FabricJS?
In this tutorial, we are going to learn how to set the minimum allowed scale of 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. Similarly, we can also set its minimum allowed scale by using the minScaleLimit property. Syntax new fabric.Textbox(text: String, { minScaleLimit : Number }: Object) Parameters text − This parameter accepts a String which is the ...
Read MoreHow to create a canvas with IText using FabricJS?
In this tutorial, we are going to learn about how to create a canvas with an IText object 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 true for ...
Read MoreFabricJS – How to remove the current object transform in a cloned image?
In this tutorial, we are going to learn how to remove the current object transform (scale, angle, flip and skew) in a cloned image using FabricJS. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to remove the current object transform in a cloned image, we use the withoutTransform property. Syntax cloneAsImage(callback: function, { withoutTransform: Boolean }: Object): fabric.Object Parameters callback (optional) − This parameter ...
Read MoreExplain Asynchronous vs Deferred JavaScript
When loading JavaScript files, the browser normally pauses HTML parsing to download and execute scripts. This can slow down page loading, especially with large JavaScript files. The async and defer attributes solve this problem by changing how scripts are loaded and executed. Normal Script Loading By default, scripts block HTML parsing until they finish downloading and executing: The browser stops parsing HTML, downloads the script, executes it, then continues parsing. This can create delays, especially with large scripts. Async Attribute The async attribute downloads scripts in parallel with HTML parsing. Once ...
Read MoreExplain Promise.race() with async-await in JavaScript?
Promise.race() executes multiple promises concurrently and returns the result of whichever promise settles first, whether resolved or rejected. Unlike Promise.all(), it doesn't wait for all promises to complete. Syntax Promise.race(iterable) .then(result => { // Handle first settled promise }) .catch(error => { // Handle if first promise rejected }); // With async/await async function example() { try { const result = await Promise.race([promise1, promise2, promise3]); // Use result from first ...
Read More