Articles on Trending Technologies

Technical articles with clear explanations and examples

Counting duplicates and aggregating array of objects in JavaScript

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

Counting duplicates and aggregating arrays of objects is a common task in JavaScript data processing. This involves identifying duplicate elements and creating new structures that group and count related data. Understanding the Problem The goal is to transform an array of objects by grouping similar items and counting occurrences. For example, if we have users with different skills, we want to group by skill and collect all users for each skill. What is Aggregating Array of Objects? Aggregation combines multiple objects into a summarized structure. Instead of having duplicate entries, we group related data together with ...

Read More

Finding whether a number is triangular number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 491 Views

Triangular numbers are sequences of numbers that can form an equilateral triangle. The nth triangular number is the sum of the first n natural numbers, calculated as T(n) = n × (n + 1) / 2. Triangular Numbers Pattern: T(1) = 1 T(2) = 3 ...

Read More

Just smaller number with monotone digits in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 209 Views

In JavaScript, finding the largest number with monotonically increasing digits that is less than or equal to a given number is a common algorithmic problem. A number has monotonically increasing digits when each digit is greater than or equal to the previous digit. What are Monotonically Increasing Digits? An integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x ≤ y. For example, 1234 and 1139 have monotone increasing digits, while 332 does not. Problem Statement We need to write a JavaScript function that takes a number ...

Read More

How to set the border scale factor of Triangle using FabricJS?

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

In this tutorial, we are going to set the border scale factor of Triangle using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we will have to create an instance of fabric.Triangle class and add it to the canvas. The borderScaleFactor property controls the thickness of the selection border that appears when an object is actively selected on the canvas. This property is particularly useful when you need to make selection borders more visible or adjust them for better user experience. Syntax new fabric.Triangle({ borderScaleFactor: Number }: ...

Read More

How to add line height to multiline text in Text using FabricJS?

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

In this tutorial, we are going to learn about how to add line height to multiline text in 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, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can add extra height between lines by using the lineHeight property. Syntax new fabric.Text(text: String, { lineHeight: Number }: Object) ...

Read More

Picking the odd one out in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 615 Views

We are required to write a JavaScript function that takes in an array of literals that contains all similar elements but one. Our function should return the unlike number. Therefore, let's write the code for this function − Example The code for this will be − const arr = [2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]; // considering that the length of array is at least 3 const findUnlike = arr => { for(let i = 1; i < arr.length-1; i++){ ...

Read More

Sort Array of objects by two properties in JavaScript

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

Sorting an array of objects by multiple properties is a common task in JavaScript. This involves first sorting by the primary property, then by the secondary property when the primary values are equal. Understanding the Problem When working with arrays of objects, we often need to sort by multiple criteria. For example, sorting employees by department first, then by salary within each department. JavaScript's Array.sort() method with a custom comparator function makes this possible. The key is to create a comparison function that first checks the primary property, and only compares the secondary property when the primary ...

Read More

Converting miles per gallon to kilometer per liter in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 639 Views

Converting miles per gallon (MPG) to kilometers per liter (km/L) is a common unit conversion in JavaScript applications dealing with fuel efficiency across different measurement systems. Understanding the Conversion To convert MPG to km/L, we need two conversion factors: 1 mile = 1.609344 kilometers 1 gallon = 4.54609188 liters (Imperial gallon) The conversion formula is: km/L = MPG × (1.609344 ÷ 4.54609188) Example Implementation const num = 25; const converter = (mpg) => { let LITRES_PER_GALLON = 4.54609188; let KILOMETERS_PER_MILE = 1.609344; ...

Read More

Retrieving the decimal part only of a number in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 3K+ Views

Precision and accuracy play vital roles in numerical computations, and in JavaScript programming, the ability to extract the decimal part of a number is a crucial skill. Whether it is for rounding, comparison, or further manipulation, retrieving only the decimal part of a number can significantly enhance the precision and control over calculations. Problem Statement Given a number in JavaScript, retrieve the decimal part only and return it as a separate number. Sample Input: num = 3.14159 Sample Output: ...

Read More

Finding state after all collisions in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

Problem We are required to write a JavaScript function that takes in an array, arr, that represents the positions of different asteroids in a one-dimensional space. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Our function is supposed to find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If both are the same size, both will explode. Two asteroids moving in the same direction will never meet. Example Input ...

Read More
Showing 15441–15450 of 61,297 articles
Advertisements