Articles on Trending Technologies

Technical articles with clear explanations and examples

Problem: Time taken by tomatoes to rot in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 219 Views

Problem We are required to write a JavaScript function that takes in a 2-D array of numbers, arr, as the only argument. The numbers in the array can be: the value 0 which represents an empty cell; the value 1 which represents a fresh tomato; the value ...

Read More

Encoding string based on character frequency in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 273 Views

We are required to write a JavaScript function that takes in a string as an argument and creates a new string based on character frequency. Each character in the new string is '(' if that character appears only once in the original string, or ')' if that character appears more than once. The comparison should be case-insensitive. Problem Statement Given a string, encode each character as: '(' - if the character appears only once ')' - if the character appears more than once Ignore case when counting character frequency For example, if the input is ...

Read More

How to create an Ellipse with progress cursor on hover over objects using FabricJS?

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

In this tutorial, we are going to create an Ellipse with a progress cursor on hover over objects using FabricJS. Progress is one of the native cursor styles available, which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize etc. which are reusing the native cursor underhood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Ellipse({ hoverCursor: String }: Object) Parameters ...

Read More

How to create a Textbox with dash pattern border using FabricJS?

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

In this tutorial, we are going to create a Textbox with a dash pattern border using FabricJS. We can customize, stretch or move around the text written in a textbox. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. We can change the appearance of the dashes of border, by using the borderDashArray property. However, our textbox object must have borders in order for this property to work. If the hasBorders property is assigned a false value, this property will not work. Syntax new ...

Read More

How to find all elements in a given array except for the first one using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn how to get all elements from an array except the first one using JavaScript. This is a common operation when you need to remove or skip the first element while processing array data. There are two main approaches to accomplish this task: Using the slice() Method (Recommended) The slice() method creates a shallow copy of a portion of an array. When called with index 1, it returns all elements starting from the second element. Syntax array.slice(startIndex) Example ...

Read More

How to check the type of a variable or object in JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 12K+ Views

JavaScript is a loosely typed programming language, meaning there is no such rule to declare the variable type. A variable can store multiple data types in a program, so it is essential to understand the variable type before using it. In JavaScript, we can use the typeof operator to check the type of a variable or object. The typeof operator takes a variable and returns its type in a string format. In addition to the typeof operator, JavaScript also provides the instanceof operator to check the type of a variable or object. The instanceof operator accepts two arguments: the ...

Read More

How to find all partitions of a multiset, where each part has distinct elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 285 Views

Finding all partitions of a multiset where each part contains distinct elements is a complex combinatorial problem. We need to create an algorithm that generates all possible ways to divide elements into groups without repetition within each group. Let's say we have an array with repeated elements: const arr = [A, A, B, B, C, C, D, E]; We need to find all combinations that use the entire array, where no elements are repeated within each partition. Example Partitions [A, B, C, D, E] [A, B, C] [A, B, C, D] [A, ...

Read More

Sorting numbers in descending order but with `0`s at the start JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 546 Views

We are required to write a JavaScript function that takes in an array of numbers. The function should sort the array of numbers on the following criteria: If the array contains any zeros, they should all appear in the beginning. All the remaining numbers should be placed in a decreasing order. For example, if the input array is: const arr = [4, 7, 0, 3, 5, 1, 0]; Then after applying the sort, the array should become: const output = [0, 0, 7, 5, ...

Read More

Parts of array with n different elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 232 Views

We are required to write a JavaScript function that takes in an array of literals, arr, as the first argument. The second argument to our function will be a number, num. Our function should count and return the number of subarrays of the array that contains exactly num distinct elements. Problem Statement Given an array and a number, find all subarrays that contain exactly that many distinct elements. For example, if the input to the function is: const arr = [12, 15, 12, 15, 18]; const num = 2; Then the output should ...

Read More

Array index to balance sums in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 631 Views

Finding a balance point in an array means locating an index where the sum of elements on the left equals the sum of elements on the right. This is a common array manipulation problem in JavaScript. Problem Statement We need to write a JavaScript function that takes an array of integers and returns the index where the left sum equals the right sum. If no such index exists, return -1. For example, with the array [1, 2, 3, 4, 3, 2, 1], index 3 is the balance point because: Left side (indices 0-2): 1 + ...

Read More
Showing 14631–14640 of 61,297 articles
Advertisements