Articles on Trending Technologies

Technical articles with clear explanations and examples

Levenshtein Distance in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 9K+ Views

The Levenshtein distance is a string metric for measuring the difference between two sequences. It represents the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into another. Understanding Levenshtein Distance Consider these two strings: const str1 = 'hitting'; const str2 = 'kitten'; The Levenshtein distance between these strings is 3 because we need three edits: kitten → hitten (substitute "h" for "k") hitten → hittin (substitute "i" for "e") hittin → hitting (insert "g" at the end) ...

Read More

Breaking integer to maximize product in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 181 Views

In JavaScript, finding the maximum product by breaking an integer into parts is a classic dynamic programming problem. We need to split a number into at least two chunks that sum to the original number while maximizing their product. Problem Statement Given an integer num, break it into at least two positive integers whose sum equals num and maximize the product of these integers. For example, if num = 10, we can break it into 3 + 3 + 4 = 10, and the product 3 × 3 × 4 = 36 is maximum possible. Algorithm ...

Read More

Finding nth element of an increasing sequence using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 311 Views

Consider an increasing sequence which is defined as follows: The number seq(0) = 1 is the first one in seq. For each x in seq, then y = 2 * x + 1 and z = 3 * x + 1 must be in seq too. There are no other numbers in seq. Therefore, the first few terms of this sequence will be: [1, 3, 4, 7, 9, 10, 13, 15, 19, 21, 22, 27, ...] We are required to write a function ...

Read More

Finding two numbers given their sum and Highest Common Factor using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

We are required to write a JavaScript function that takes in two numbers. The first number represents the sum of two numbers and second represents their HCF (GCD or Greatest Common Divisor). Our function should find and return those two numbers. Problem Given the sum and HCF of two numbers, we need to find the original two numbers. For two numbers to have a specific HCF, both numbers must be multiples of that HCF. Mathematical Approach If two numbers a and b have HCF h, then: a = h × m and b = ...

Read More

How to add stroke to a Rectangle using FabricJS?

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

In this tutorial, we are going to learn how to add stroke to a Rectangle using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. Our rectangle object can be customized in various ways like changing its dimensions, adding a background colour or by changing the colour of the line drawn around the object. We can do this by using the stroke property. Syntax new fabric.Rect({ stroke : String }: Object) ...

Read More

How to get the scaled width of Text using FabricJS

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

In this tutorial, we are going to learn how to get the scaled width of Text using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can also find the object's scaled width by using the getScaledWidth method. Syntax getScaledWidth() Example 1: Using the getScaledWidth Method Let's see ...

Read More

How to create your first chart with FusionCharts.js?

Mukul Latiyan
Mukul Latiyan
Updated on 15-Mar-2026 704 Views

FusionCharts is a JavaScript library that you can use when you want to create charts and maps and put them in your web application. In this tutorial, we will show how you can use FusionChart.js to create two different charts. Before we learn how to create charts, the first important thing is to know how we can install FusionCharts onto our local machines. Installing FusionCharts There are multiple ways with which we can install FusionCharts. Using CDN You can use the CDN link given below to directly gain access to the files of FusionCharts. ...

Read More

How to create own Ajax functionality?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 435 Views

An Ajax (Asynchronous JavaScript and XML) request is an HTTP request made using JavaScript, typically with the XMLHttpRequest object, to exchange data with a server and update a specific part of a web page without requiring full page refresh. There are two ways to create own Ajax functionality: using JSONPlaceholder API or your own file. Using JSONPlaceholder API JSONPlaceholder is a free online REST API that you can use to test and practice your development skills. Syntax Users can follow the below syntax for creating an Ajax request using JavaScript's "XMLHttpRequest" object. let xhr ...

Read More

How to get substring between two similar characters in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 4K+ Views

In JavaScript, extracting a substring between two similar characters is a common task when parsing strings. This article explores different methods to achieve this using built-in string methods. Understanding String Methods Before diving into the solution, let's understand the key methods we'll use: The substring() method extracts characters between two indices and returns a new string without modifying the original. Syntax string.substring(start, end) The split() method divides a string into an array of substrings based on a specified separator. Syntax string.split(separator, limit) Method 1: Using split() ...

Read More

Reduce an array to groups in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 263 Views

In JavaScript, you can group consecutive duplicate elements in an array using the reduce() method. This technique combines adjacent duplicate values while preserving the original order. Problem Statement Given an array with duplicate entries, we need to merge consecutive duplicate elements together: const arr = ['blue', 'blue', 'green', 'blue', 'yellow', 'yellow', 'green']; console.log("Input array:", arr); Input array: [ 'blue', 'blue', 'green', 'blue', 'yellow', 'yellow', 'green' ] The expected output should combine only consecutive duplicates: [ 'blueblue', 'green', 'blue', 'yellowyellow', 'green' ] Using Array.reduce() Method The reduce() ...

Read More
Showing 15971–15980 of 61,297 articles
Advertisements