Articles on Trending Technologies

Technical articles with clear explanations and examples

How to sort array according to age in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 511 Views

We are required to write a JavaScript function that takes in an array of numbers representing ages of some people. Then the function should bring all the ages less than 18 to the front of the array without using any extra memory. Understanding the Problem We need to sort an array so that all minors (ages < 18) appear before adults (ages ≥ 18), while maintaining the original order within each group. Example The code for this will be − const ages = [23, 56, 56, 3, 67, 8, 4, 34, 23, 12, ...

Read More

Finding the index position of an array inside an array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 351 Views

When working with arrays of arrays in JavaScript, you might need to find the index position of a specific sub-array within the main array. This is useful for checking if a particular array exists and determining its location. Suppose we have an array of arrays like this: const arr = [ [1, 0], [0, 1], [0, 0] ]; We need to write a JavaScript function that takes an array of arrays as the first argument and a target array as the second argument. The function should ...

Read More

Average with the Reduce Method in JavaScript

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

In JavaScript, calculating the average of array elements using the reduce() method is an efficient and elegant approach. The reduce() method iterates through the array once to compute the sum, which we then divide by the array length. Understanding the Problem We need to calculate the average value of all elements in an array using JavaScript's reduce() method. For example, given the array [1, 2, 3, 4, 5], the average would be (1 + 2 + 3 + 4 + 5) / 5 = 15 / 5 = 3. Algorithm Step 1: Create a function that ...

Read More

Trim off '?' from strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 231 Views

We are required to write a JavaScript function that takes in a string as the only argument. The string is likely to contain question marks (?) in the beginning and the end. The function should trim off all these question marks from the beginning and the end keeping everything else in place. For example − If the input string is − const str = '??this is a ? string?'; Then the output should be − 'this is a ? string' Method 1: Using Regular Expressions The simplest approach uses ...

Read More

Finding nth element of the Padovan sequence using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 356 Views

Padovan Sequence The Padovan sequence is a sequence of integers P(n) defined by the initial values: P(0) = P(1) = P(2) = 1 and the recurrence relation: P(n) = P(n-2) + P(n-3) The first few values of P(n) are: 1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200, 265, ... Problem We need to write a JavaScript function that takes in a number n and returns the nth term of the Padovan sequence. Using Iterative Approach The most efficient approach uses iteration to calculate the sequence step by step: const padovan = (num = 1) => { // Handle base cases if (num

Read More

How to lock the vertical skewing of a Circle using FabricJS?

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

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

Read More

How to lock the rotation of a Triangle using FabricJS?

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

In this tutorial, we are going to learn how to lock the rotation 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 rotate or not. This can be done by using the lockRotation property. Syntax new fabric.Triangle({ lockRotation : Boolean }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our ...

Read More

How to make a text path in IText invisible using FabricJS?

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

In this tutorial, we are going to learn about how to make a text path in IText invisible 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 lines automatically. This is not true for ...

Read More

How to calculate the date three months prior using JavaScript?

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

To calculate the date three months prior using JavaScript, we will first need to create a new date object, which will represent the current date. We will then use the setMonth() method to subtract 3 from the current month. Finally, we will convert this new date object back to a string using the toString method to display the date three months prior. Basically, we will be writing a dynamic JavaScript function that can take in a number as its input and return the date prior to that number of months from today's date. For example − ...

Read More

Grouping array values in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 559 Views

Suppose we have an array of objects containing some years and weeks data like this: const arr = [ {year: 2017, week: 45}, {year: 2017, week: 46}, {year: 2017, week: 47}, {year: 2017, week: 48}, {year: 2017, week: 50}, {year: 2017, week: 52}, {year: 2018, week: 1}, {year: 2018, week: 2}, {year: 2018, week: 5} ]; We are required to ...

Read More
Showing 15251–15260 of 61,298 articles
Advertisements