Front End Technology Articles

Page 400 of 652

How to print positive and negative infinity values in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

In JavaScript, infinity values represent numbers that exceed the maximum finite value. JavaScript provides built-in constants to handle positive and negative infinity values. JavaScript Infinity Constants JavaScript has two built-in constants for infinity values: Infinity or Number.POSITIVE_INFINITY - represents positive infinity -Infinity or Number.NEGATIVE_INFINITY - represents negative infinity Basic Example JavaScript Infinity Values JavaScript Infinity Values ...

Read More

Rotating an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 619 Views

In JavaScript, rotating an array means moving elements from one position to another by a specified number of steps. This operation is useful for circular data structures and algorithmic problems. For example, if we have an array [12, 6, 43, 5, 7, 2, 5] and rotate it by 3 positions to the left, the result would be [5, 7, 2, 5, 12, 6, 43]. Method 1: Using Array Prototype Extension We can extend the Array prototype to add a rotation method: // Helper function to rotate by one position const rotateByOne = arr => { ...

Read More

Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 191 Views

We are required to write a JavaScript function that takes in three numbers A, B and N, and finds the total number of N-digit numbers whose sum of digits at even positions and odd positions are divisible by A and B respectively. Understanding the Problem For an N-digit number, we need to: Calculate sum of digits at even positions (0-indexed) Calculate sum of digits at odd positions (0-indexed) Check if even position sum is divisible by A Check if odd position sum is divisible by B Helper Function: Calculate Position-wise Sums First, let's ...

Read More

Finding how many time a specific letter is appearing in the sentence using for loop, break, and continue - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 176 Views

We are required to write a JavaScript function that finds how many times a specific letter is appearing in the sentence using for loop, break, and continue statements. Using continue Statement The continue statement skips the current iteration and moves to the next one. Here's how we can use it to count character occurrences: const string = 'This is just an example string for the program'; const countAppearances = (str, char) => { let count = 0; for(let i = 0; i < str.length; i++){ ...

Read More

Count groups of negatives numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 461 Views

We have an array of numbers like this: const arr = [-1, -2, -1, 0, -1, -2, -1, -2, -1, 0, 1, 0]; Let's say, we are required to write a JavaScript function that counts the consecutive groups of negative numbers in the array. Like here we have consecutive negatives from index 0 to 2 which forms one group and then from 4 to 8 forms the second group. So, for this array, the function should return 2. Understanding the Problem A group of consecutive negative numbers is defined as: One ...

Read More

Compare array of objects - JavaScript

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

We have two arrays of objects like these: const blocks = [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, ] const containers = [ { block: { id: 1 } }, { block: { id: 2 } }, { block: { id: 3 } }, ] We are required to write a function that checks each object of blocks array with the block key of each ...

Read More

Delete duplicate elements based on first letter – JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 194 Views

We need to write a JavaScript function that removes duplicate strings based on their first letter, keeping only the first occurrence of each starting letter. For example, if we have an array like: const arr = ['Apple', 'Jack', 'Army', 'Car', 'Jason']; We should keep only one string for each starting letter. Since 'Apple' and 'Army' both start with 'A', we keep only 'Apple' (first occurrence). Similarly, 'Jack' and 'Jason' both start with 'J', so we keep only 'Jack'. Problem with Direct Array Modification The original approach has a bug - modifying an array ...

Read More

Take two numbers m and n & return two numbers whose sum is n and product m in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 256 Views

We need to write a JavaScript function that takes two numbers m (product) and n (sum) and returns two numbers whose sum equals n and product equals m. If no such numbers exist, the function should return false. This is essentially solving a quadratic equation where we need to find two numbers x and y such that x + y = n and x × y = m. Mathematical Approach We can solve this using the quadratic formula. If x + y = n and x × y = m, then x and y are roots of ...

Read More

Finding if three points are collinear - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 717 Views

Three or more points that lie on the same straight line are called collinear points. In JavaScript, we can determine if three points are collinear by checking if they have the same slope between each pair of points. Mathematical Concept Three points A, B, and C are collinear if the slope between any two pairs is equal: slope of AB = slope of BC = slope of AC Slope Formula For two points A(x1, y1) and B(x2, y2), the slope is calculated as: Slope = (y2 - y1) / (x2 - ...

Read More

Pronic numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 316 Views

A Pronic number is a number which is the product of two consecutive integers, that is, a number of the form n(n + 1). For example, 6 is a Pronic number because 6 = 2 × 3, and 12 is Pronic because 12 = 3 × 4. We are required to write a JavaScript function that takes in a number and returns true if it is a Pronic number otherwise returns false. Understanding Pronic Numbers The first few Pronic numbers are: 0, 2, 6, 12, 20, 30, 42, 56, 72, 90... ...

Read More
Showing 3991–4000 of 6,519 articles
« Prev 1 398 399 400 401 402 652 Next »
Advertisements