AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 331 of 840

How to add default horizontal scaling to a canvas-type text with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 405 Views

We can add default horizontal scaling to canvas text by using the scale() method on the 2D rendering context. This method transforms all subsequent drawing operations, including text, by scaling them horizontally and vertically. HTML Canvas HTML canvas is a 2D drawing surface that allows developers to create dynamic graphics, charts, and animations using JavaScript. The canvas element provides a powerful API for drawing shapes, text, and images directly in the browser. The canvas element acts as a container for graphics and can be manipulated using the Canvas API to create rich, interactive user experiences without external ...

Read More

Deleting the last vowel from a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 294 Views

We are required to write a JavaScript function that takes in a string and returns a new string with the last vowel of each word removed. For example: If the string is − const str = 'This is an example string'; Then the output should be − const output = 'Ths s n exampl strng'; Therefore, let's write the code for this function − Example The code for this will be − const str = 'This is an example string'; const removeLast = word => { ...

Read More

Finding number plate based on registration number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 703 Views

The car registering system of a city assigns unique identifiers to customers and corresponding number plates to their vehicles. We need to create a JavaScript function that converts a customer ID into its corresponding number plate format. Problem Statement The car registration system assigns two types of identifiers: Customer ID − A natural number between 0 and 17, 558, 423 (inclusive), assigned sequentially starting from 0 Number Plate − Contains a series ...

Read More

All right triangles with specified perimeter in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

We are required to write a JavaScript function that takes in a number that specifies the perimeter for a triangle. Our function should return an array of all the right triangle side triplets whose perimeter matches the specified input. Understanding Right Triangles A right triangle satisfies the Pythagorean theorem: a² + b² = c², where c is the hypotenuse (longest side). For a given perimeter P, we need a + b + c = P. Algorithm Approach We use three nested loops to check all possible combinations of triangle sides. For each triplet, we verify: ...

Read More

Finding maximum length of common subarray in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 417 Views

Finding the maximum length of a common subarray (also known as the longest common subarray) is a classic dynamic programming problem. We need to find the longest contiguous sequence that appears in both arrays in the same order. Problem Statement We are required to write a JavaScript function that takes in two arrays of literals, arr1 and arr2, as the first and the second argument respectively. Our function should return the maximum length of a subarray that appears in both arrays. For example, if the input arrays are: const arr1 = [1, 2, 3, 2, ...

Read More

Dynamic programming to check dynamic behavior of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 603 Views

We are required to write a JavaScript function that takes in an array of strings, ordered by ascending length. The function should return true if, for each pair of consecutive strings, the second string can be formed from the first by adding a single letter either at the beginning or end. For example: If the array is given by − const arr = ["c", "ca", "can", "acan", "acane", "dacane"]; Then our function should return true because: "ca" = "c" + "a" (adding "a" at the end) ...

Read More

Finding sum of all numbers within a range in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 820 Views

Problem We are required to write a JavaScript function that takes in an array that specifies a range. Our function should find and return the sum of all the natural numbers falling in the range including the range numbers. Example Following is the code − const range = [4, 67]; const findSum = ([l, h]) => { let sum = 0; for(let i = l; i { // Formula: Sum = n * (first + last) / 2 // where ...

Read More

Return the nearest greater integer of the decimal number it is being called on in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 297 Views

The Math.ceil() function returns the smallest integer greater than or equal to a given number. This means it "rounds up" to the nearest integer. Syntax Math.ceil(x) Parameters x: A number to round up to the nearest integer. Return Value Returns the smallest integer greater than or equal to the given number. If the input is not a number, returns NaN. Example: Basic Usage console.log(Math.ceil(4.3)); // 5 console.log(Math.ceil(4.8)); // 5 console.log(Math.ceil(5.0)); // 5 (already integer) console.log(Math.ceil(-2.3)); // -2 console.log(Math.ceil(-2.8)); // -2 ...

Read More

Product of subarray just less than target in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 189 Views

We are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument, and a number, target, as the second argument. Our function is supposed to count and return the number of (contiguous) subarrays where the product of all the elements in the subarray is less than target. Problem Example For example, if the input to the function is: const arr = [10, 5, 2, 6]; const target = 100; The expected output is: 8 The 8 subarrays that have product less ...

Read More

How does inline JavaScript work with HTML?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 7K+ Views

In this article, you will understand how inline JavaScript works with HTML. Inline JavaScript represents a code block written in between the tags in an HTML file. The advantage of using inline JavaScript in HTML files is to reduce the round trip of the web browser to the server. What is Inline JavaScript? Inline JavaScript is JavaScript code that is embedded directly within HTML documents using tags. This approach allows you to execute JavaScript without creating separate .js files, making it convenient for small scripts and quick implementations. Example 1: Basic Inline JavaScript Let ...

Read More
Showing 3301–3310 of 8,392 articles
« Prev 1 329 330 331 332 333 840 Next »
Advertisements