Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-4 votes
1 answer
75 views

Rewriting nested loop with reduce [closed]

I wrote the below code to solve a prep test, found online. The goal is to find the min absolute difference between numbers in an array. function minimumAbsoluteDifference(arr: number[]): number { /...
Igor Shmukler's user avatar
-1 votes
2 answers
74 views

2d array - group by first item and calculate average of corresponding number

I have a 2d array which contains a list of series with title, rating, and time spent watching. For example: let seriesList = [["Squid Game", 3.5, "4 days"], ["Squid Game",...
amy's user avatar
  • 83
4 votes
3 answers
99 views

Why has my array element been changed by this declaration?

Javascript code: const bigArray2 = [ [1, 2, 3], [2, 4, 6], [3, 6, 9], ]; //creates single-layer array containing all elements of every array within bigArray2 const combinedArray = ...
Jake's user avatar
  • 49
2 votes
3 answers
130 views

Correct way to return first element of a JS array that meets condition and mapped

Let's say we have a function that makes expensive calculation and an array of source values for which we do the calculation. We want to get a first return value of the function that is not falsy and ...
quadracik's user avatar
-2 votes
1 answer
139 views

FlatMap vs Reduce for extracting data from a nested object

I have a dataset as such, where there may be multiple testResults array elements, along with there being 1 or many response array elements; and I an wanting to extract all of the potential ...
physicsboy's user avatar
  • 6,398
2 votes
9 answers
377 views

Create 2 arrays with reduce method

I have an array of objcets. With reduce method after looping i want to receive two seperate arrays. Now, i am doing this way. const dogs = [ { weight: 22, curFood: 250, owners: ['Alice', 'Bob'] }, ...
Zuka Kharati's user avatar
0 votes
7 answers
125 views

Array of objects reducing based on multiple parameters

Need to reduce an array of Objects to return the highest value of the same name. Need the following, [ { name: 'a', value: 20, ...(other object values) }, { ...
caiovisk's user avatar
  • 3,818
1 vote
2 answers
59 views

Aggregate multiple values in of javascript

I want to reduce an array of objects like this: var data = [{ item: "Item 1", pages: 30, chapters: 3 }, { item: "Item 1", pages: 50, chapters: 3 ...
Ikzer's user avatar
  • 539
1 vote
1 answer
217 views

Angular material table multiple header rows mapping

There is a sample of data table which consists of multiple header rows | | Song 1 | Song 2 | Song 3 | |---------------------------|----------------|----------------| |...
corry's user avatar
  • 1,529
-1 votes
1 answer
150 views

Using reduce() alters the original array in JavaScript depite docs claiming otherwise

I'm declaring the following array. let arr = [ { id:"aa", vals:[1,2,3] }, { id:"cc", vals:[3,4,5] }, { id:"bb", vals:[2,3,4] }]; Printing it in the console ...
Konrad Viltersten's user avatar
-4 votes
1 answer
64 views

Create array based on nested array [closed]

I have an array like that const arr = [ [1, 0], [0, 2], [0, 1], [0, 1] ] I want to reduce it and get a new array. My aim is getting values of nested array by index. [[index(0)],[index(1)] const new ...
nihat onal's user avatar
0 votes
2 answers
313 views

Is it possible to have two accumulators with the reduce method?

Is it possible to have two accumulators with the reduce method? I need to pass another const inside my reduce. I want to do the same as const one with const two. Do I have to create a new method or ...
user avatar
1 vote
2 answers
97 views

I have an array of percentages I want to find the average to [duplicate]

I'm using React JS, and I'm trying to find the average of this array: [ "75.0%", "50.0%", "66.66666666666666%", "66.66666666666666%", "...
PhuongHoang68's user avatar
0 votes
0 answers
38 views

Substring issue when combined with map or reduce. Am I doing something wrong?

According to spec, when a second argument is omitted, substring should return n characters from the end of the string. If embedded in an array map or reduce, substring with a single argument seems to ...
bensullivan's user avatar
1 vote
1 answer
67 views

How to rearrange a object with multiple levels based on groups and ascending order?

I need to rearrange a chained object to a non-chained one. So, I need to create more objects to represent this. basicaly I have this: 1. Person (code:1) (level 1) 1.2 Person (code:2) (level 2) 1.2....
Jonathan Reis's user avatar

15 30 50 per page
1
2 3 4 5
127