Web Development Articles

Page 308 of 801

Largest sum of subarrays in JavaScript

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

Finding the maximum sum subarray is a classic algorithmic problem in JavaScript. Given an array of numbers, we need to find the contiguous subarray with the largest sum. This problem is commonly known as the Maximum Subarray Problem and has practical applications in data analysis and optimization. Problem Statement Given an array of integers, find the contiguous subarray with the maximum sum. For example, given the array: [-3, 4, 2, -1, 6, -5, 3, -2, 7, 1] The maximum subarray sum would be: 15 This comes from the subarray [4, ...

Read More

Number pattern in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 5K+ Views

Number patterns in JavaScript are essential for developers who want to create visually appealing outputs and understand algorithmic thinking. These patterns involve generating sequences of numbers that follow specific rules or arrangements, helping developers grasp mathematical concepts that underlie complex algorithms. What are Number Patterns? Number patterns are sequences of numbers arranged in specific formations, typically displayed in triangular or pyramid structures. Each pattern follows a mathematical rule that determines how numbers are positioned and incremented. Pattern 1: Zero-Padded Triangle This pattern creates a triangular structure where each row contains numbers from 1 to the row ...

Read More

Picking index randomly from array in JavaScript

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

In JavaScript, randomly selecting an index from an array is a common requirement for applications that need unpredictable behavior, such as shuffling content, random sampling, or creating dynamic user experiences. This article explores several effective methods to achieve this functionality. Problem Statement We need an efficient way to randomly select an index from a JavaScript array, where each index has an equal probability of being chosen. JavaScript doesn't provide a built-in method for this, so we'll implement our own solutions. Sample Input: Consider an array: let arr = [12, 45, 7, 89, 34, 56] Sample Output: ...

Read More

Returning reverse array of integers using JavaScript

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

In JavaScript, creating an array of integers in reverse order (from a number down to 1) is a common programming task. This article explores multiple approaches to generate descending arrays efficiently, from basic loops to built-in array methods. Problem Statement Create a JavaScript function that generates an array of natural numbers starting from a given number and descending down to 1. Sample Input: const num = 5; Sample Output: const output = [5, 4, 3, 2, 1]; Method 1: Using For Loop The most straightforward approach uses a decrementing for ...

Read More

Validating a password using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 4K+ Views

Password validation is a critical security feature in web applications. JavaScript provides powerful tools to implement client-side password validation that checks for complexity requirements like length, character types, and special symbols. This helps ensure users create strong passwords that protect their accounts from unauthorized access. Problem Statement We need to create a JavaScript function that validates passwords based on these criteria: Password length must be between 6 and 20 characters Must contain at least one digit (0-9) Must contain at least one lowercase letter (a-z) Must contain at ...

Read More

Constructing an array of smaller elements than the corresponding elements based on input array in JavaScript

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

In JavaScript, constructing an array where each element represents the count of smaller numbers to the right is a common algorithmic problem. This technique is useful for data analysis, ranking systems, and competitive programming challenges. Problem Statement Given an input array of numbers, create an output array where each element represents the count of numbers smaller than the current element and located to its right in the input array. Sample Input: Input Array: [5, 2, 6, 1] Sample Output: Output Array: [2, 1, 1, 0] For element 5: two ...

Read More

Function that returns the minimum and maximum value of an array in JavaScript

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

Finding the minimum and maximum values in an array is a fundamental task in JavaScript programming. Whether you're analyzing data, implementing algorithms, or building interactive applications, having efficient methods to determine array extremes is essential. Problem Statement Create a JavaScript function that takes an array of numbers as input and returns both the minimum and maximum values. The function should handle arrays of any length efficiently. Sample Input: const inputArray = [5, 2, 9, 1, 7, 4]; Sample Output: const minValue = 1; const maxValue = 9; Using Math.min() and Math.max() ...

Read More

Repeating string for specific number of times using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 2K+ Views

JavaScript provides several methods to repeat a string for a specific number of times. This functionality is useful for generating patterns, creating padding, or building repeated text sequences in web applications. Problem Statement Write a JavaScript function that takes a string and a positive integer as input and returns a new string that repeats the input string for the specified number of times. If the input string is empty or the specified number of times is zero, the function should return an empty string. Sample Input: String: "Hello" Number of Times: 3 Sample Output: ...

Read More

Representing seconds in HH:MM:SS in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 3K+ Views

Converting seconds to HH:MM:SS format is a common requirement in JavaScript applications for displaying durations, timers, and time intervals in a readable format. This article explores three practical methods to achieve this conversion. Problem Statement Given a number representing the duration in seconds, the task is to write a JavaScript function that converts the given duration into the format HH:MM:SS, where HH represents hours, MM represents minutes, and SS represents seconds. Sample Input: const durationInSeconds = 3665; Sample Output: 01:01:05 In this case, the input durationInSeconds is 3665, which represents a ...

Read More

Retrieving the decimal part only of a number in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 3K+ Views

Precision and accuracy play vital roles in numerical computations, and in JavaScript programming, the ability to extract the decimal part of a number is a crucial skill. Whether it is for rounding, comparison, or further manipulation, retrieving only the decimal part of a number can significantly enhance the precision and control over calculations. Problem Statement Given a number in JavaScript, retrieve the decimal part only and return it as a separate number. Sample Input: num = 3.14159 Sample Output: ...

Read More
Showing 3071–3080 of 8,010 articles
« Prev 1 306 307 308 309 310 801 Next »
Advertisements