Articles on Trending Technologies

Technical articles with clear explanations and examples

Moving all zeroes present in the array to the end in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 606 Views

We are required to write a JavaScript function that takes in an array of literals that might contain some 0s. Our function should tweak the array such that all the zeroes are pushed to the end and all non-zero elements hold their relative positions. Problem Given an array containing zeros and non-zero elements, we need to move all zeros to the end while maintaining the relative order of non-zero elements. Method 1: Using Two-Pass Approach This approach first collects non-zero elements, then adds zeros at the end: const arr = [5, 0, 1, 0, ...

Read More

Greatest number divisible by n within a bound in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 419 Views

Problem We need to write a JavaScript function that takes in a divisor number n and a bound number b. Our function should find the largest integer num, such that: num is divisible by n (the divisor) num is less than or equal to b (the bound) num is greater than 0 Brute Force Approach The straightforward approach is to iterate through all multiples of n and find the largest one within the bound: const n = 14; const b = 400; const biggestDivisible = ...

Read More

process.chdir() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 7K+ Views

The process.chdir() method changes the current working directory of the Node.js process. It throws an exception if the operation fails (such as when the specified directory doesn't exist) but returns no value on success. Syntax process.chdir(directory) Parameters directory – A string containing the path to the directory you want to change to. Return Value This method returns undefined on success and throws an error if the directory change fails. Example 1: Successful Directory Change // Node.js program to demonstrate process.chdir() const process = ...

Read More

How to create a Rectangle with wait cursor on hover over objects using FabricJS?

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

In this tutorial, we are going to create a Rectangle with a wait cursor on hover over objects using FabricJS. wait 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., that reuse the native cursor under the hood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Rect({ hoverCursor: String }: Object) Parameters Options ...

Read More

How to set the background colour of text lines with Text using FabricJS?

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

In this tutorial, we are going to learn how to set the background colour of text lines with Text 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. Similarly we can also set the background colour of text lines by using the textBackgroundColor property. Syntax new fabric.Text(text: String , { textBackgroundColor ...

Read More

Apply an IF condition to every element in an HTML table with JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 5K+ Views

HTML tables are created using the tag with for table rows and for data cells. JavaScript allows you to apply conditional logic to each table element dynamically. This article demonstrates how to use JavaScript to apply if conditions to every element in an HTML table, enabling dynamic content modification based on specific criteria. Using document.querySelectorAll() with forEach() The document.querySelectorAll() method returns a static NodeList of all elements matching the specified CSS selector. Combined with forEach(), it allows you to iterate through table elements and apply conditions. Syntax document.querySelectorAll(selector).forEach(function(element) { ...

Read More

Make strings in array become keys in object in a new array in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

The task we are going to perform in this article is to make strings in an array become keys in objects within a new array in JavaScript. Let's consider a simple array: let array = ['bike', 'car']; We want to transform this array into a new array where each string becomes a key in an object with an empty array as its value: let newArray = [{bike: []}, {car: []}]; Let's explore different methods to accomplish this transformation in JavaScript. Using map() Method The map() method creates a new array ...

Read More

Reduce array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 250 Views

In JavaScript, arrays can be transformed using various methods. This article demonstrates how to extract and convert time values from an array of objects into a more usable format. Suppose we have an array of objects containing time strings: const arr = [ {"time":"18:00:00"}, {"time":"10:00:00"}, {"time":"16:30:00"} ]; We need to create a function that: Extracts the time strings from each object Converts times like "18:00:00" to arrays like [18, 0] Returns an array containing all converted time arrays Using map() to Transform ...

Read More

Finding all possible ways of integer partitioning in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 822 Views

The partition of a positive integer n is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition. For example, 4 can be partitioned in five distinct ways: 4 3 + 1 2 + 2 2 + 1 + 1 1 + 1 + 1 + 1 We are required to write a JavaScript function that takes in a positive integer as the only argument. The function should find and return all the possible ways of partitioning that ...

Read More

All ways of balancing n parenthesis in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 208 Views

Problem We are required to write a JavaScript function that takes in a number n. Our function should return an array showing all the ways of balancing n parenthesis. For example, for n = 3, the output will be: ["()()()", "(())()", "()(())", "(()())", "((()))"] Approach We use a recursive backtracking approach where we keep track of how many opening and closing parentheses we can still use. At each step, we can add an opening parenthesis if we have any left, or a closing parenthesis if it would create a valid balance. Example ...

Read More
Showing 16071–16080 of 61,297 articles
Advertisements