Articles on Trending Technologies

Technical articles with clear explanations and examples

Checking for a Doubleton Number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 429 Views

A "doubleton number" is a natural number that contains exactly two distinct digits. For example, 23, 35, 100, and 12121 are doubleton numbers because they each use only two different digits. Numbers like 123 (three digits) and 9980 (three digits: 9, 8, 0) are not doubleton numbers. Problem Statement We need to write a JavaScript function that takes a number and returns true if it's a doubleton number, false otherwise. Solution The approach is to convert the number to a string, track unique digits using an object, and check if exactly two distinct digits exist. ...

Read More

Constructing full name from first name, last name and optional middle name in JavaScript

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

We need to write a JavaScript function that takes in three strings: first name, last name, and an optional middle name, then returns the full name constructed from these inputs. Problem The challenge is handling the optional middle name parameter. If no middle name is provided, we should construct the full name with just the first and last names, avoiding extra spaces. Using Array Filter Method This approach uses an array to collect all name parts, filters out empty values, and joins them with spaces: const firstName = 'Vijay'; const lastName = 'Raj'; ...

Read More

Splitting a string into maximum parts in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 423 Views

In JavaScript, partitioning a string into maximum parts means dividing it so that each letter appears in only one partition. This creates the maximum number of non-overlapping sections possible. Problem Statement We need to write a JavaScript function that takes a string and partitions it into as many parts as possible, where each letter appears in at most one part. The function returns an array of integers representing the size of these parts. Input Example: const str = "ababcbacadefegdehijhklij"; Expected Output: [9, 7, 8] Explanation: The partitions are "ababcbaca" ...

Read More

How to set the angle of skew on x-axis of Rectangle using FabricJS?

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

In this tutorial, we are going to learn how to set the angle of skew on the x-axis of 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 color or by changing the angle of skew on the x-axis. We can do this by using the skewX property. Syntax new fabric.Rect({ skewX: Number ...

Read More

How to cancel running animations in Line using FabricJS?

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

In this tutorial, we are going to learn about how to cancel running animations in Line using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to cancel running animations, we use the dispose method. Syntax dispose() Without using ...

Read More

How to convert a pixel value to a number value using JavaScript?

Prerna Tiwari
Prerna Tiwari
Updated on 15-Mar-2026 5K+ Views

Converting pixel values to number values in JavaScript is a common task in web development when working with CSS properties, element positioning, or calculations. Pixel values like "100px" need to be converted to numeric values like 100 for mathematical operations. When positioning and styling items on a web page, you often need to work with both pixel and numeric values. For instance, you might need to convert a pixel value such as "100px" to a number value like 100 to perform calculations or operations. This article explores different methods to convert pixel values to numbers using JavaScript. Method ...

Read More

Generating random string of specified length in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 589 Views

We are required to write a JavaScript function that takes in a number n and returns a random string of length n containing no other than the 26 English lowercase alphabets. Therefore, let's write the code for this function − Example The code for this will be − const num = 8; const randomNameGenerator = num => { let res = ''; for(let i = 0; i < num; i++){ const random = Math.floor(Math.random() * 26); ...

Read More

Split array entries to form object in JavaScript

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

In JavaScript, converting array entries into objects is a common task. This article explores multiple approaches to split array elements and transform them into key-value pairs or structured objects. Understanding the Problem We need to convert array elements into objects. This can involve splitting string elements into key-value pairs or simply transforming array indices into object keys. Let's explore different methods to achieve this. Using reduce() and split() Methods This method splits array entries by a delimiter and groups them with counts, useful for data aggregation. Example // Define data in the form ...

Read More

Converting number of corresponding string without using library function in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 447 Views

Converting a number to a string without using built-in functions like String() or toString() requires extracting individual digits and building the result character by character. Problem We need to write a JavaScript function that takes a number and converts it to its corresponding string representation without using the built-in functions String() or toString() or direct string concatenation. Approach The solution extracts digits from right to left using the modulo operator (%) and integer division. Each digit is converted to its character representation and prepended to build the final string. Example const num = ...

Read More

Finding the height based on width and screen size ratio (width:height) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 791 Views

We are required to write a JavaScript function that takes in the width of the screen as the first argument and the aspect ratio (w:h) as the second argument. Based on these two inputs our function should return the height of the screen. Understanding Aspect Ratios An aspect ratio defines the proportional relationship between width and height. Common ratios include 16:9 (widescreen), 4:3 (traditional), and 21:9 (ultrawide). The formula is: height = (width × ratio_height) / ratio_width. Example Following is the code − const ratio = '18:11'; const width = 2417; const findHeight ...

Read More
Showing 15421–15430 of 61,298 articles
Advertisements