Web Development Articles

Page 197 of 801

Detecting the largest element in an array of Numbers (nested) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 264 Views

We need to find the largest number in a nested array of any depth. This problem requires recursion to traverse through all nested levels and compare each number to find the maximum value. For example, if we have this nested array: const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], ...

Read More

Performing power operations on an array of numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 475 Views

We need to write a JavaScript function that takes an array of integers with even length and performs a specific power operation to find two numbers whose squares sum to a calculated value. Problem Statement Given an array of integers with even length, we calculate: num = (arr[0]² + arr[1]²) × (arr[2]² + arr[3]²) × ... × (arr[n-2]² + arr[n-1]²) Our function should return an array [A, B] such that A² + B² = num. Example Walkthrough For array [1, 2, 3, 4]: First pair: 1² + 2² = 1 ...

Read More

Picking the largest elements from multidimensional array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

Given a multidimensional array, we need to pick the largest elements from each subarray in JavaScript. The multidimensional arrays are arrays inside an array. Whenever there are arrays inside the array, it works as a multidimensional array. Following is a one-dimensional array: const arr = ["Welcome", "to", "tutorials", "point"]; const numbers = [1, 5, 12, 67, 99]; This is how a multidimensional array looks like: const array = [["Mike tyson", "Vijay"], ["ananya", "charmee"], ["Lion", "Tiger"]]; This is how we can access elements from a multidimensional array: ...

Read More

Greatest element in a Multi-Dimensional Array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 199 Views

We have to write a simple function in JavaScript that takes in an array of Numbers (nested to any level) and return the greatest number present in the array. Problem Example If the input array is: const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], ...

Read More

Finding the product of array elements with reduce() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 991 Views

We are required to write a JavaScript function that takes in an array and finds the product of all its elements using the reduce() method. Understanding reduce() for Products The reduce() method executes a reducer function on each array element, accumulating results into a single value. For multiplication, we start with an initial value of 1 and multiply each element. Syntax array.reduce((accumulator, currentValue) => { return accumulator * currentValue; }, 1); Example: Basic Product Calculation const arr = [3, 1, 4, 1, 2, -2, -1]; const ...

Read More

Removing duplicates and inserting empty strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 348 Views

We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end. Problem Description If we find 4 duplicate values we have to remove them all and insert four empty strings at the end. This maintains the original array length while eliminating duplicates. How It Works The algorithm uses reduce() to iterate through the array. For each element, it checks if the current index matches the last occurrence using lastIndexOf(). If yes, it's the final occurrence and gets added to the ...

Read More

Encoding decimal to factorial and back in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 398 Views

The factorial number system uses factorials as bases instead of powers. Each digit position represents a factorial base, where the rightmost digit is base 0!, the next is base 1!, then base 2!, and so on. How Factorial Encoding Works In factorial representation, the nth digit from the right can range from 0 to n. For example: Position 0 (rightmost): 0 to 0, multiplied by 0! = 1 Position 1: 0 to 1, multiplied by 1! = 1 Position 2: 0 to 2, multiplied by 2! = ...

Read More

Filter array based on another array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 14K+ Views

In this article, we are going to learn how to filter an array based on another array in JavaScript. An Array in JavaScript is used to store different elements. These elements are stored at contiguous memory locations. By using index numbers, we can access any or each data element present in the array. Index numbers start from 0. Syntax Following is the syntax of the array in JavaScript – const array_name = [item1, item2, ...]; The following is a simple declaration of array in JavaScript: const colors = ['Blue', 'Limegreen', 'Orange', ...

Read More

Constructing a nested JSON object in JavaScript

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

In JavaScript, we often need to construct nested objects from structured data. This article demonstrates how to build a nested JSON object from a string containing paired characters. Problem Statement Given a string with characters in pairs, we need to construct a nested object where each pair becomes a code property, and each level has a sub-object for the next pair. Input string: const str = "AABBCCDDEE"; Expected output structure: const obj = { code: "AA", sub: { ...

Read More

Difference between numbers and string numbers present in an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 425 Views

In JavaScript, arrays can contain both numbers and string representations of numbers. This article demonstrates how to differentiate between these types and perform different operations based on their type. Problem We need to create a JavaScript function that takes a mixed array of numbers and string representations of integers. The function should add up all numeric values and subtract the sum of string numeric values from this total. Approach We'll use typeof to identify data types and the unary plus operator (+) to convert strings to numbers while checking if they're valid numeric strings. Example ...

Read More
Showing 1961–1970 of 8,010 articles
« Prev 1 195 196 197 198 199 801 Next »
Advertisements