Aayush Mohan Sinha

Aayush Mohan Sinha

89 Articles Published

Articles by Aayush Mohan Sinha

Page 3 of 9

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

Largest sum of subarrays in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 465 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

Picking index randomly from array in JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 863 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

Calculating the area of a triangle using its three sides in JavaScript

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

In JavaScript, calculating the area of a triangle using its three sides can be accomplished through mathematical formulas. This is useful when you know the side lengths but not the height or base measurements. Problem Statement Create a JavaScript function that calculates the area of a triangle given the lengths of its three sides. Sample Input: Side A: 3 units Side B: 4 units Side C: 5 units Sample Output: Area: 6 Approach We'll explore two mathematical methods to solve this problem: ...

Read More

Sorting numbers in ascending order and strings in alphabetical order in an array in JavaScript

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

In JavaScript, sorting arrays that contain both numbers and strings requires a custom approach since the default sort() method converts all elements to strings. This article explores two effective methods to sort mixed arrays with numbers first (ascending) followed by strings (alphabetical). Problem Statement We need to create a JavaScript function that sorts an array containing both numbers and strings. The requirements are: Numbers should appear before strings Numbers should be sorted in ascending order Strings should be sorted alphabetically Sample Input: ["zebra", 21, "apple", 5, "orange", 13, "banana", 2] Sample ...

Read More

Counting matching substrings in JavaScript

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

Counting matching substrings in JavaScript is essential for text analysis and string manipulation tasks. This article explores different methods to count subsequences within a string, helping developers choose the most appropriate approach for their needs. Problem Statement We need a JavaScript function that counts subsequences in a given string. The function takes a string "str" and an array of strings "arr" as input. It examines each element in "arr" and determines how many strings are subsequences of "str". A subsequence is formed by removing characters from the original string while maintaining the relative order of remaining characters. ...

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

Finding the only unique string in an array using JavaScript

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

In JavaScript, finding a unique string that appears only once in an array is a common programming challenge. This article demonstrates two effective approaches to solve this problem. Problem Statement Write a JavaScript function that takes an array of strings as input and returns the only unique string present in the array. A unique string is defined as a string that occurs only once in the given array. If there are no unique strings, the function should return null. Sample Input: const strings = ["apple", "banana", "orange", "banana", "kiwi", "kiwi", "apple"]; Sample Output: ...

Read More

Returning reverse array of integers using JavaScript

Aayush Mohan Sinha
Aayush Mohan Sinha
Updated on 15-Mar-2026 277 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

Calculate the value of (m)1/n in JavaScript

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

In JavaScript, calculating the nth root of a number (m^(1/n)) is a common mathematical operation used in various applications. The nth root is the inverse of exponentiation - for example, the cube root of 27 is 3 because 3³ = 27. Understanding the nth Root The nth root of a number m is written as m^(1/n), where: m is the base number n is the root degree The result is the number that, when raised to the power n, equals m Syntax Math.pow(base, exponent) // For nth root: Math.pow(m, 1/n) Using ...

Read More
Showing 21–30 of 89 articles
« Prev 1 2 3 4 5 9 Next »
Advertisements