Articles on Trending Technologies

Technical articles with clear explanations and examples

Compare two arrays of single characters and return the difference? JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 582 Views

We are required to compare, and get the difference, between two arrays containing single character strings appearing multiple times in each array. Example of two such arrays are: const arr1 = ['A', 'C', 'A', 'D']; const arr2 = ['F', 'A', 'T', 'T']; We will check each character at the same position and return only the parts who are different. Approach The algorithm compares elements at the same index position. When characters differ, both are added to the result array. Any remaining elements from the longer array are also included. Example ...

Read More

JavaScript Sum odd indexed and even indexed elements separately and return their absolute difference

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

For a given list of elements, write a JavaScript program to find the sum of its odd and even indexed elements and then, calculate difference between them. To solve this problem, we will first separate odd indexed and even indexed elements. After separating them find their sum separately and store it in different variables. Now, we will calculate the difference between these sums to get desired result. Example Scenario: Input: list = [11, 21, 31, 41, 51, 61]; Output: difference = 30 Here, odd-indexed items are [21, 41, 61] and their sum is ...

Read More

Insert a character at nth position in string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 708 Views

We are required to write a JavaScript function that takes in a string as the first argument and a number as the second argument and a single character as the third argument, let's call this argument char. The number is guaranteed to be smaller than the length of the array. The function should insert the character char after every n characters in the string and return the newly formed string. For example − If the arguments are − const str = 'NewDelhi'; const n = 3; const char = ' '; Then the ...

Read More

Mean of an array rounded down to nearest integer in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 449 Views

Problem We need to write a JavaScript function that takes an array of numbers and returns the average (mean) of the array rounded down to the nearest integer using Math.floor(). Example Following is the code − const arr = [45, 23, 67, 68, 12, 56, 99]; const roundedMean = (arr = []) => { const { sum, count } = arr.reduce((acc, val) => { let { sum, count } = acc; count++; ...

Read More

How to make a circle invisible using FabricJS?

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

In this tutorial, we are going to learn how to make a Circle invisible using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we have to create an instance of fabric.Circle class and add it to the canvas. Our circle object can be customized in various ways like changing its dimensions, adding a background color or by making it visible or invisible. We can do this by using the visible property. Syntax new fabric.Circle({ visible: Boolean }) Parameters ...

Read More

How to lock the vertical movement of Triangle using FabricJS?

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

In this tutorial, we are going to learn how to lock the vertical movement of a Triangle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a triangle object in the canvas, we can also specify whether we want it to move only in the X-axis. This can be done by using the lockMovementY property. Syntax new fabric.Triangle({ lockMovementY: Boolean }: Object) Parameters ...

Read More

How to move an object to the top of the stack of drawn objects in IText using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we are going to learn about how to move an object to the top of the stack of drawn objects in IText using FabricJS. The IText class was introduced in FabricJS version 1.4, extends fabric.Text and is used to create IText instances. An IText instance gives us the freedom to select, cut, paste or add new text without additional configurations. There are also various supported key combinations and mouse/touch combinations which make text interactive which are not provided in Text. Textbox, however, which is based on IText allows us to resize the text rectangle and wraps ...

Read More

Comparing the performance of recursive and looped factorial function in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 330 Views

We will be writing two JavaScript functions, the job of both the functions will be to take in a number and return its factorial. The first function should make use of a for loop or while loop to compute the factorial. Whereas the second function should compute the factorial using a recursive approach. Lastly, we should compare the times taken by these functions over a large number of iterations. Iterative Factorial Function The iterative approach uses a simple for loop to calculate the factorial: const factorial = (num = 1) => { ...

Read More

How to make the controlling corners of a Circle transparent using FabricJS?

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

In this tutorial, we are going to learn how to make the controlling corners of Circle transparent using FabricJS. Circle is one of the various shapes provided by FabricJS. In order to create a circle, we will create an instance of fabric.Circle class and add it to the canvas. The transparentCorners property allows us to control whether the selection corners are transparent or opaque. Syntax new fabric.Circle({ transparentCorners: Boolean }: Object) Parameters options (optional) − This parameter is an Object which provides additional ...

Read More

How to lock the vertical scaling of Rectangle using FabricJS?

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

In this tutorial, we are going to learn how to lock the vertical scaling of a Rectangle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a rectangle object in the canvas, we can also specify whether we want to stop scaling an object vertically. This can be done by using the lockScalingY property. Syntax new fabric.Rect({ lockScalingY: Boolean }) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this ...

Read More
Showing 15261–15270 of 61,298 articles
Advertisements