Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create a style tag using JavaScript?

Prerna Tiwari
Prerna Tiwari
Updated on 15-Mar-2026 8K+ Views

JavaScript allows developers to create and manipulate style tags dynamically to change the appearance of a webpage. By using the document.createElement() method, the .sheet property, and the .insertRule() and .deleteRule() methods, we can add, modify, and remove CSS rules from a stylesheet. This enables creating dynamic and interactive web pages that respond to user interactions. One of the most powerful features of JavaScript is the ability to manipulate the DOM, which is the structure of a web page. Creating and modifying style tags using JavaScript provides a flexible way to control styling programmatically. Creating a Style Tag ...

Read More

Sorting the numbers from within in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 204 Views

We are required to write a JavaScript function that takes in an array of numbers and reorders the digits of all the numbers internally in a specific order (let's say in ascending order for the sake of this problem). For example: If the array is − const arr = [543, 65, 343, 75, 567, 878, 87]; Then the output should be − const output = [345, 56, 334, 57, 567, 788, 78]; Therefore, let's write the code for this function − Example The code for this will be − ...

Read More

Algorithm to sum ranges that lie within another separate range in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 182 Views

We have two sets of ranges; one is a single range of any length (R1) and the other is a set of ranges (R2) some or parts of which may or may not lie within the single range (R1). We need to calculate the sum of the ranges in (R2) - whole or partial - that lie within the single range (R1). Problem Breakdown For each range in R2, we calculate the overlapping portion with R1 and sum all overlaps: const R1 = [20, 40]; const R2 = [[14, 22], [24, 27], [31, 35], [38, ...

Read More

Manipulate Object to group based on Array Object List in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 361 Views

Grouping objects in JavaScript is a common operation when working with arrays of objects. This technique allows you to organize data by specific properties, making it easier to process and analyze related items together. Understanding the Problem Consider an array of objects representing people with properties like name, profession, and age. We want to group these objects by a specific property (like profession) to create an organized structure where each group contains all objects sharing that property value. For example, grouping people by profession would create separate arrays for developers, teachers, engineers, etc. This organization makes it ...

Read More

Building a lexicographically increasing sequence of first n natural numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 182 Views

We are required to write a JavaScript function that takes in a number n and returns an array containing the first n natural numbers. The condition is that the numbers should be sorted lexicographically, which means all numbers starting with 1 should come before any starting with 2, 3, 4, and so on. Understanding Lexicographical Ordering Lexicographical ordering treats numbers as strings. For example, "10" comes before "2" because "1" comes before "2" alphabetically. This creates the sequence: 1, 10, 11, 12, ..., 19, 2, 20, 21, ..., etc. Example Implementation const num = 24; ...

Read More

Sorting array based on increasing frequency of elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 340 Views

We need to write a JavaScript function that sorts an array based on the frequency of elements. Elements with lower frequency appear first, and elements with the same frequency are sorted in ascending order. Problem Given an array that might contain duplicates, we want to sort it so that: Elements appearing fewer times come first Elements with the same frequency are sorted in ascending order For example, if the input is: const arr = [5, 4, 5, 4, 2, 1, 12]; The expected output is: [1, 2, 12, ...

Read More

Changing the npm start-script of Node.js

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

The start-script of a Node.js application consists of all the commands that will be used to perform specific tasks. When starting or initializing a Node.js project, there are predefined scripts that will be created for running the application. These scripts can be changed as per the need or demand of the project. Script commands are widely used for making different startup scripts of programs in both Node and React. npm start is used for executing a startup script without typing its execution command. Package.json File Structure The start script needs to be added in the package.json file. ...

Read More

How to Create a Profit and Loss Calculator using HTML, CSS, and JavaScript?

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

In this article, we are going to create a profit and loss calculator using JavaScript. We will be using basic math formulas to calculate the profit and loss, returning the result in percentage along with the actual values. To calculate profit and loss, we need two values: CP (Cost Price) and SP (Selling Price). Formulas to Calculate Profit and Loss Profit: SP − CP Profit Percentage: (Profit/CP) × 100 Loss: CP − SP Loss Percentage: (Loss/CP) × 100 Creating the Calculator ...

Read More

How to set the fill colour of a Triangle using FabricJS?

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

In this tutorial, we are going to learn how we can change the appearance of a Triangle object by changing its fill colour 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. We can change the fill colour by using the fill property which allows us to specify the colour of the object's fill. Syntax new fabric.Triangle({ fill: String }: Object) ...

Read More

How to create infix to postfix converter in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 1K+ Views

An infix to Postfix converter is a tool that converts an infix expression to a postfix expression. In this tutorial, we will build the infix to postfix converter using JavaScript. What is an infix expression? Infix expression is an expression in which the operators are between the operands. For example, the expression "3 + 4" is an infix expression. What is a postfix expression? A postfix expression is an expression in which the operators are after the operands. For example, the expression "3 4 +" is a postfix expression. How does the Infix to Postfix converter work? ...

Read More
Showing 15491–15500 of 61,297 articles
Advertisements