Articles on Trending Technologies

Technical articles with clear explanations and examples

Maximum difference between a number JavaScript

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

In this problem statement, our task is to write a function for finding the maximum difference between two numbers in an array using JavaScript. We'll explore both a brute force approach and an optimized solution. Understanding the Problem We need to find the maximum difference between any two numbers in an array where the larger number appears after the smaller number in the array order. For example, in array [2, 3, 5, 6, 4, 1], the maximum difference is 4 (6 - 2 = 4), not 5 (6 - 1), because 1 comes after 6. Method 1: ...

Read More

Check whether we can form string2 by deleting some characters from string1 without reordering the characters of any string - JavaScript

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

In this problem, we need to determine whether we can form string2 by removing some characters from string1 without changing the order of characters in either string. This is essentially checking if string2 is a subsequence of string1. Understanding the Problem We want to check if the second string can be formed from the first string while preserving character order. Let's look at some examples: // Example 1: Can form "ale" from "apple" let s1 = "apple"; let s2 = "ale"; console.log("Can form '" + s2 + "' from '" + s1 + "'?"); // Expected: ...

Read More

Forming and matching strings of an array based on a random string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 359 Views

In JavaScript, we can check if strings from an array can be formed using characters from a given string. This involves counting character frequencies and matching them against each array element. Problem Statement Given an array of strings and a random string, find the first string from the array that can be completely formed using the characters available in the random string. const arr = ['Dinesh', 'Mahesh', 'Rohit', 'Kamal', 'Jatin Sapru', 'Jai']; const str = 'lsoaakjm'; console.log("Array:", arr); console.log("Available characters:", str); Array: [ 'Dinesh', 'Mahesh', 'Rohit', 'Kamal', 'Jatin Sapru', 'Jai' ] Available ...

Read More

Bring number down to 1 in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 140 Views

Problem We need to write a JavaScript function that takes a number and finds the minimum operations to reduce it to 1 using these rules: If the number is even, divide it by 2 If the number is odd, add 1 or subtract 1 The function should return the minimum number of operations required. Example For input number 7, the output should be 4 operations: Input: 7 Output: 4 Output Explanation The optimal path requires 4 steps: 7 → 8 → 4 → 2 → 1 ...

Read More

Finding the sum of all numbers in the nth row of an increasing triangle using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 299 Views

For the purpose of this problem, an increasing triangle is a structure where numbers are arranged in rows, with each row containing one more number than the previous row, and all numbers are consecutive starting from 1. Understanding the Triangle Structure The increasing triangle looks like this: 1 2 3 4 5 6 7 8 9 10 Each row n contains n consecutive numbers. Row 1 has 1 number, row 2 has 2 numbers, row 3 has 3 numbers, and so on. Problem Statement We need ...

Read More

How to set the padding of an Ellipse using FabricJS?

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

In this tutorial, we are going to learn how to set the padding 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 padding of an ellipse object. This can be done by using the padding property. Syntax new fabric.Ellipse({ padding : Number }: Object) ...

Read More

How to set the padding of Textbox using FabricJS?

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

In this tutorial, we are going to learn how to set the padding of a Textbox using FabricJS. Textbox is one of the various shapes provided by FabricJS. 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 padding of a textbox object. This can be done by using the padding property. Syntax new fabric.Textbox(text: String, { padding : Number }: Object) ...

Read More

FabricJS – How to scale an Image object to a given height?

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

In this tutorial, we are going to learn how to scale an Image object to a given height 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 scale an Image object to a given height, we use the scaleToHeight method. Syntax scaleToHeight(value: Number, absolute: Boolean): fabric.Object Parameters value − This parameter accepts a Number which determines ...

Read More

Extract a number from a string using JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 37K+ Views

In JavaScript, there are multiple ways to extract a number from a string. One way is to use the match() method and a regular expression to search for all numeric digits in the string. Another way is to use the replace() method and a regular expression to remove all nonnumeric characters from the string, leaving only the numbers. Let's understand each of the methods with the help of some examples. Using the match() method and regular expression The regular expression is one kind of search pattern which we can create by combining multiple alphabetic and special characters. ...

Read More

How to Become a JavaScript Developer?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 440 Views

A JavaScript developer is a programmer who specializes in creating interactive and dynamic web applications using JavaScript, the world's most popular programming language. JavaScript developers build everything from simple website interactions to complex single-page applications, mobile apps, and even server-side applications using Node.js. JavaScript developers work on both front-end development (user-facing interfaces) and back-end development (server-side logic). They collaborate with designers, other developers, and stakeholders to create responsive, user-friendly web experiences that run seamlessly across different browsers and devices. Essential Skills for JavaScript Developers To become a successful JavaScript developer, you'll need to master several core technologies ...

Read More
Showing 15121–15130 of 61,297 articles
Advertisements