Front End Technology Articles

Page 196 of 652

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

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 275 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

Encoding decimal to factorial and back in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 410 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

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 203 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

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

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 437 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

Removing duplicates and inserting empty strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 355 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

Replacing vowels with their 1-based index in a string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 673 Views

We are required to write a JavaScript function that takes in a string and replaces all occurrences of the vowels in the string with their index in the string (1-based). It means if the second letter of the string is a vowel, it should be replaced by 2. Example Following is the code − const str = 'cancotainsomevowels'; const replaceVowels = (str = '') => { const vowels = 'aeiou'; let res = ''; for(let i = 0; i < str.length; i++){ ...

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

Finding a number, when multiplied with input number yields input number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 201 Views

We need to write a JavaScript function that takes a positive integer n and a positive integer p, then finds a value k such that the sum of digits raised to successive powers equals k * n. Problem Statement Given a number n with digits a, b, c, d... and a power p, we want to find integer k where: (a^p + b^(p+1) + c^(p+2) + d^(p+3) + ...) = n * k If such k exists, return k; otherwise return -1. Example Walkthrough For number 695 and p = 2: 6^2 + ...

Read More
Showing 1951–1960 of 6,519 articles
« Prev 1 194 195 196 197 198 652 Next »
Advertisements