Articles on Trending Technologies

Technical articles with clear explanations and examples

Finding a number, when multiplied with input number yields input number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 198 Views

We need to write a JavaScript function that takes a positive integer n and a positive integer p, then finds a value k such that the sum of digits raised to successive powers equals k * n. Problem Statement Given a number n with digits a, b, c, d... and a power p, we want to find integer k where: (a^p + b^(p+1) + c^(p+2) + d^(p+3) + ...) = n * k If such k exists, return k; otherwise return -1. Example Walkthrough For number 695 and p = 2: 6^2 + ...

Read More

Using Kadane’s algorithm to find maximum sum of subarray in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 716 Views

Kadane's algorithm is a powerful dynamic programming technique used to find the maximum sum of a contiguous subarray within an array. This algorithm is particularly useful for solving problems involving sequences of numbers where you need to find the optimal contiguous subsequence. Problem Statement Given an array of integers, find the contiguous subarray with the maximum sum and return that sum. Sample Input: arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4] Sample Output: Maximum sum: 6 (from subarray [4, -1, 2, 1]) Method 1: Naive Approach The ...

Read More

How to create an Ellipse with a background color using FabricJS?

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

In this tutorial, we are going to create an Ellipse with background color using FabricJS. Ellipse is one of the various shapes provided by FabricJS. In order to create an ellipse, we have to create an instance of fabric.Ellipse class and add it to the canvas. The backgroundColor property allows us to assign a color to our object's background. It is the color of the container where the ellipse lives and is rectangular in shape for ellipse. Syntax new fabric.Ellipse({ backgroundColor: String }: Object) Parameters ...

Read More

How to change the font style of a Textbox using FabricJS?

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

In this tutorial, we are going to see how to change the font style of a Textbox 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. Font style refers to the style of characters typed within a textbox. Syntax new fabric.Textbox(text: String, { fontStyle: String }: Object) Parameters text − This parameter accepts a String ...

Read More

How to Create Pong Game in JavaScript?

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

A Pong game is a two-player paddle game where each player's task is to save the ball from hitting the wall. Whenever player 1 hits the ball at the opponent's wall then player one will receive a point, and similarly, player 2 will get a point if he/she hits the ball at the opponent's wall. In this tutorial, we will create a Pong Game in JavaScript using HTML5 Canvas. Game Controls Before implementing the game, let's understand the controls: Left Player: Use 'Z' key to move up and 'S' key to move down ...

Read More

How to validate email address using RegExp in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 15K+ Views

Anyone can make a mistake while entering the email in the input field. So, it's the developer's responsibility to check if users have entered a valid email string. Many libraries are available to validate email addresses, which we can use with various JavaScript frameworks, but not with vanilla JavaScript. However, if we want to use any library, we need to use its CDN. Here, we will use the regular expression to validate the email address in vanilla JavaScript. Basic Email Validation Pattern We have used the below regular expression pattern in our first example to validate the email. ...

Read More

Dynamic Programming: return all matched data in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 373 Views

Dynamic programming in JavaScript can be used to efficiently search and retrieve data from nested structures. This article demonstrates how to search for all matching cities in a complex JSON object containing country and province information. The Data Structure We have a nested JSON object with countries, provinces, and cities: const countryInfo = { country: [{ name: "Bangladesh", province: [{ name:"Dhaka", ...

Read More

Finding upper elements in array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 187 Views

We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return an array of all the elements from the input array that are greater than or equal to the number taken as the second argument. Therefore, let's write the code for this function — Using for Loop The most straightforward approach uses a for loop to iterate through the array and check each element: const arr = [56, 34, 2, 7, 76, 4, 45, 3, ...

Read More

Finding all possible combined (plus and minus) sums of n arguments JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 391 Views

We need to write a JavaScript function that takes any number of arguments (all numbers) and finds the sum closest to zero from all possible combinations of addition and subtraction. For example, with arguments 1, 2, 3, the possible combinations are: 1 + 2 + 3 = 6 1 - 2 - 3 = -4 1 + 2 - 3 = 0 1 - 2 + 3 = 2 The function should return the sum closest to 0, which in this case is 0. Algorithm Approach We use a Set to store all ...

Read More

Counting number of 9s encountered while counting up to n in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 448 Views

We need to write a JavaScript function that counts how many times the digit "9" appears when counting from 0 to a given number n. For example, counting from 0 to 100 includes numbers like 9, 19, 29, 90, 91, 99, etc., where "9" appears multiple times. Problem We are required to write a JavaScript function that takes in a number n. Our function should count and return the number of times we will have to use the digit 9 while counting from 0 to n. Example Following is the code − const num ...

Read More
Showing 14581–14590 of 61,297 articles
Advertisements