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
Reducing array elements to all odds in JavaScript
We need to write a JavaScript function that transforms an array by converting all numbers to odd values. The transformation rules are: If the number is odd, leave it unchanged. If the number is even, subtract 1 from it to make it odd. This ensures all elements in the resulting array are odd numbers. Example Here's how to implement this transformation: const arr = [5, 23, 6, 3, 66, 12, 8]; const reduceToOdd = (arr = []) => { const res = []; ...
Read MoreHow to set the colour of controlling corners of a Triangle using FabricJS?
In this tutorial, we are going to set the colour of the controlling corners of Triangle using FabricJS. The cornerColor property allows us to manipulate the colour of the controlling corners when the object is active. Syntax new fabric.Triangle({ cornerColor: String }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our triangle. Using this parameter, properties such as colour, cursor, stroke width, and a lot of other properties can be changed related to the object of ...
Read MoreHow to add linethrough to Text using FabricJS?
In this tutorial, we are going to learn about how to add linethrough text decoration to a Text object 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, font family, line height which can be obtained by the properties textAlign, fontFamily and lineHeight respectively. We can add linethrough by using the linethrough property. Syntax new fabric.Text(text: String , { linethrough: Boolean }: Object) Parameters ...
Read MoreHow to create a JSON representation of a Line object using FabricJS?
In this tutorial, we are going to learn about how to create a JSON representation of a Line object 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 create a JSON representation of a Line object, we use the toJSON method. ...
Read MoreHow to add default horizontal scaling to a canvas-type text with JavaScript?
We can add default horizontal scaling to canvas text by using the scale() method on the 2D rendering context. This method transforms all subsequent drawing operations, including text, by scaling them horizontally and vertically. HTML Canvas HTML canvas is a 2D drawing surface that allows developers to create dynamic graphics, charts, and animations using JavaScript. The canvas element provides a powerful API for drawing shapes, text, and images directly in the browser. The canvas element acts as a container for graphics and can be manipulated using the Canvas API to create rich, interactive user experiences without external ...
Read MoreHow to create a function from a string in JavaScript?
Creating a function from a string in JavaScript can be helpful in situations when you need to generate a function dynamically at runtime or when you have a string that contains the code for a function you wish to execute. JavaScript provides several methods to create functions from strings, each with different security implications and use cases. The most common approaches are using eval(), the Function() constructor, and Function.prototype.constructor. Approach 1: Using the eval() Function The JavaScript eval() method is one of the easiest ways to build a function from a string. This powerful function can execute ...
Read MoreDeleting the last vowel from a string in JavaScript
We are required to write a JavaScript function that takes in a string and returns a new string with the last vowel of each word removed. For example: If the string is − const str = 'This is an example string'; Then the output should be − const output = 'Ths s n exampl strng'; Therefore, let's write the code for this function − Example The code for this will be − const str = 'This is an example string'; const removeLast = word => { ...
Read MoreFinding number plate based on registration number in JavaScript
The car registering system of a city assigns unique identifiers to customers and corresponding number plates to their vehicles. We need to create a JavaScript function that converts a customer ID into its corresponding number plate format. Problem Statement The car registration system assigns two types of identifiers: Customer ID − A natural number between 0 and 17, 558, 423 (inclusive), assigned sequentially starting from 0 Number Plate − Contains a series ...
Read MoreAll right triangles with specified perimeter in JavaScript
We are required to write a JavaScript function that takes in a number that specifies the perimeter for a triangle. Our function should return an array of all the right triangle side triplets whose perimeter matches the specified input. Understanding Right Triangles A right triangle satisfies the Pythagorean theorem: a² + b² = c², where c is the hypotenuse (longest side). For a given perimeter P, we need a + b + c = P. Algorithm Approach We use three nested loops to check all possible combinations of triangle sides. For each triplet, we verify: ...
Read MoreFinding maximum length of common subarray in JavaScript
Finding the maximum length of a common subarray (also known as the longest common subarray) is a classic dynamic programming problem. We need to find the longest contiguous sequence that appears in both arrays in the same order. Problem Statement We are required to write a JavaScript function that takes in two arrays of literals, arr1 and arr2, as the first and the second argument respectively. Our function should return the maximum length of a subarray that appears in both arrays. For example, if the input arrays are: const arr1 = [1, 2, 3, 2, ...
Read More