All Questions
Tagged with reduce javascript
1,895 questions
-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 {
/...
-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",...
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 = ...
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 ...
-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 ...
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'] },
...
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)
},
{
...
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
...
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 |
|---------------------------|----------------|----------------|
|...
-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 ...
-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 ...
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 ...
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%",
"...
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 ...
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....