Web Development Articles

Page 187 of 801

How to convert array into array of objects using map() and reduce() in JavaScript

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

Converting arrays into arrays of objects is a common task in JavaScript. This article shows how to use map() and reduce() together to transform nested arrays into structured objects. Problem Statement Suppose we have an array of arrays like this: const arr = [ [ ['juice', 'apple'], ['maker', 'motts'], ['price', 12] ], [ ['juice', 'orange'], ['maker', 'sunkist'], ['price', 11] ] ]; We need to convert this nested array structure into ...

Read More

Generate Ranking with combination of strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 338 Views

We are required to write a JavaScript function that takes in any number of arrays of numbers and generates a frequency map of all possible combinations within each array. The function counts how many times each element and combination appears across all arrays. For example, if we have the following arrays: const a = [23, 45, 21], b = [45, 23], c = [21, 32], d = [23], e = [32], f = [50, 54]; The function should ...

Read More

All combinations of sums for array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 920 Views

We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a number, say n as the second argument. The number n will always be less than or equal to the length of the array. Our function should return an array of the sum of all elements of all the possible subarrays of length n from the original array. For example, If the input is: const arr = [2, 6, 4]; const n = 2; Then the output should be: const output = ...

Read More

Dynamic Programming: return all matched data in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 372 Views

Dynamic programming in JavaScript can be used to efficiently search and retrieve data from nested structures. This article demonstrates how to search for all matching cities in a complex JSON object containing country and province information. The Data Structure We have a nested JSON object with countries, provinces, and cities: const countryInfo = { country: [{ name: "Bangladesh", province: [{ name:"Dhaka", ...

Read More

Calculating quarterly and yearly average through JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 317 Views

In this tutorial, we'll learn how to calculate quarterly and yearly averages from an array of numbers using JavaScript. This involves chunking data into groups and computing their averages. Suppose we have an array of numbers like this: const arr = [1, 2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; console.log("Original array:", arr); Original array: [1, 2, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] We need to group this array ...

Read More

Array thirds with equal sums in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 181 Views

We are required to write a JavaScript function that takes in an array of integers as the first and the only argument. Our function should return true if and only if we can partition the array into three non-empty parts with equal sums, false otherwise. Problem Statement Given an array of integers, determine if it can be split into exactly three contiguous subarrays with equal sums. For example, if the input to the function is: const arr = [3, 3, 6, 5, -2, 2, 5, 1, -9, 4]; Then the output should be: ...

Read More

Group strings starting with similar number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 321 Views

In JavaScript, you can group strings that start with the same number by extracting the first part before the decimal and comparing consecutive elements. This is useful when working with version numbers, decimal classifications, or any structured string data. Problem Statement Given an array of number strings like this: const arr = ["1.1", "1.2", "1.3", "2.1", "2.2", "3.1", "3.2", "3.3", "4.1", "4.2"]; console.log("Input array:", arr); Input array: [ '1.1', '1.2', '1.3', '2.1', '2.2', '3.1', '3.2', '3.3', '4.1', '4.2' ] We need to group all strings starting with the same number into ...

Read More

Finding intersection of arrays of intervals in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 586 Views

JavaScript function that takes in two arrays, arr1 and arr2 of intervals which are pairwise disjoint and in sorted order. A closed interval [a, b] (with a

Read More

Replace all occurrence of specific words in a sentence based on an array of words in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 562 Views

We are required to write a JavaScript function that takes a string and an array of strings. Our function should return a new string, where all the occurrences of the word in the string that are present in the array are replaced by a whitespace. Our function should use the String.prototype.replace() method to solve this problem. Understanding the Problem When filtering words from a sentence, we need to: Match whole words only (not parts of words) Handle case-insensitive matching Use regular expressions ...

Read More

Finding squares in sorted order in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 310 Views

We are required to write a JavaScript function that takes in an array of integers, arr, sorted in increasing order. Our function is supposed to return an array of the squares of each number, also sorted in increasing order. For example, if the input to the function is − const arr = [-2, -1, 1, 3, 6, 8]; Then the output should be − const output = [1, 1, 4, 9, 36, 64]; The Challenge Simply squaring and sorting would work, but it's inefficient. Since the original array is ...

Read More
Showing 1861–1870 of 8,010 articles
« Prev 1 185 186 187 188 189 801 Next »
Advertisements