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
Constructing full name from first name, last name and optional middle name in JavaScript
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 MoreSplitting a string into maximum parts in JavaScript
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 MoreHow to set the angle of skew on x-axis of Rectangle using FabricJS?
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 MoreHow to cancel running animations in Line using FabricJS?
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 MoreHow to convert a pixel value to a number value using JavaScript?
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 MoreGenerating random string of specified length in JavaScript
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 MoreSplit array entries to form object in JavaScript
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 MoreConverting number of corresponding string without using library function in JavaScript
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 MoreFinding the height based on width and screen size ratio (width:height) in JavaScript
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 MoreConvert mixed case string to lower case in JavaScript
In JavaScript, there are multiple ways to convert a mixed-case string to lowercase. The most common approach is using the built-in toLowerCase() method, but you can also implement a custom solution using character codes. Using the Built-in toLowerCase() Method The simplest and most efficient way is to use JavaScript's built-in toLowerCase() method: const str = 'ABcD123'; const output = str.toLowerCase(); console.log(output); abcd123 Custom Implementation Using Character Codes For educational purposes, here's how to implement a custom convertToLower() function that converts uppercase letters (ASCII 65-90) to lowercase by adding 32 to ...
Read More