Questions tagged [reduce]

Reduce refers to the operation, where a array of items is reduced to a single value. Use with language tag like [c++], [google-sheets-formula]. Do NOT use alone.

Documentation in respective languages:

3548 questions
1
vote
4 answers

Convert array of objects to array of arrays (by attribute)

I want transform my array to array of arrays by attribute "icon". const array = [ { icon: true }, { icon: false }, { icon: false }, { icon: true }, { icon: false } ] I need: [[{icon: true}, {icon: false}, {icon: false}], [{{icon:…
user3468894
  • 65
  • 1
  • 5
1
vote
0 answers

One-line generator that acts like reduce but yields all intermediate results

I love how easy it is to implement all kinds of commonly used high-level algorithmic behavior in Python. I am now looking for an optimal way of implementing recursive sequences or any other kind of generator whose next value depends on O(1) of the…
Domi
  • 22,151
  • 15
  • 92
  • 122
1
vote
4 answers

Scala .reduce strange behaviour on generic types

I've been wondering, why this piece of code won't compile? Is there a way in Scala to create method/func that is generic parametrised and allows for such operation like 'reduce'. Is this behaviour having anything in common with type erasure or is…
dreamsComeTrue
  • 116
  • 1
  • 6
1
vote
4 answers

ES6 Sum by object property in an array

I am trying to sum the unit value by date, and create a new array where there are no duplicate dates. For example, I want to calculate the total of 2015-12-04 00:01:00. This date has occurred 2 times in the following data, its value is 5 and 6,…
Anson C
  • 507
  • 7
  • 18
1
vote
3 answers

Reduce an array into a single integer causes type error

I'm trying to take an array of Pairs(StartTime:Int, EndTime:Int) and reduce them to the accumulation of time for each session. fun main() { val sessionsInSecond = listOf>(Pair(10,12), Pair(10,15)) val timeSpan: Int =…
Joel Broström
  • 3,530
  • 1
  • 34
  • 61
1
vote
1 answer

Merge data frames based on column with different rows

I have multiple csv files that I read into individual data frames based on their name in the directory, like so # ask user for path path = input('Enter the path for the csv files: ') os.chdir(path) # loop over filenames and read into individual…
n8-da-gr8
  • 541
  • 6
  • 20
1
vote
5 answers

How would I transform this array of arrays into an array of objects using a functional style in JavaScript?

I'd appreciate some help in this problem I'm trying to solve in a particular way. I'm trying to use forEach() and reduce() to transform a dataset from one format - an array of arrays - into another - an array of objects. I know that arr.forEach(i)…
1
vote
2 answers

Reducing by (K,V) pairs and sort by V

I'm super new to pyspark and RDDs. Apologies if this question is very rudimentary. I have mapped and cleaned by data using the following code: delay = datasplit.map(lambda x: ((x[33], x[8], x[9]))).filter(lambda x: x[0]!= u'0.00').filter(lambda x:…
1
vote
0 answers

In Woo I need real stock levels to decrease when order is created and don't decrease until order cancel

I need a product stock to decrease immediately on order creation and it should not increase unless the order is cancelled (it should also not decrease a second time upon payment successful or any other switch). My problem is I want to use my…
Cranmoot
  • 51
  • 1
  • 6
1
vote
4 answers

add up numbers in array

I've been following this post but I cannot get my array to add up all numbers in my array. I use this: var array_new = [$(".rightcell.emphasize").text().split('€')]; to give me this array: array_new: ,102.80,192.60,22.16 then I do this: var…
artworkjpm
  • 1,255
  • 2
  • 19
  • 40
1
vote
2 answers

Get nested object values and put it on a table header

In the following stackblitz sample. I have the following data: My table is displaying what I want, As you can see inside the timeline object the "start" values are exactly the same as the ones inside the aval array Therefore, is there anyway I can…
brohymn
  • 460
  • 5
  • 22
1
vote
1 answer

For loop slower than reduce?

I'm getting very strange timings from this code. At times the for loop runs much more slowly. var len = 8e6 function *rands(){ for(let i =0; i < len; i++) yield Math.random() } var add = (a,b) => a + b var arr = new…
Truman Purnell
  • 253
  • 3
  • 9
1
vote
1 answer

Is it possible to find the supremum norm of a vector applying Open MPI Reduce operation with Op MPI.MAX/ MAXLOC

I need to find the supremum norm (maximal element of vector) of a vector. I can implement is using norm function of linear algebra library of mpi4py. x = np.linspace(0, 100, n) mxnorm_x = norm(x, np.inf) print "mxnorm-x", mxnorm_x However, I need…
mirzapinku
  • 61
  • 8
1
vote
0 answers

how to reduceByKey on a transformation of the key and return the whole record

I have an RDD with [String, Int] type columns, respectively. RDD values are like : ("A x",3) ("A y",4) ("A z",1) ("B y",2) ("C w",5) ("C y",2) ("E x",1) ("E z",3) What I want to accomplish is to get an RDD like this (String,Int): ("A y",4) #among…
Jimmo
  • 19
  • 3
1
vote
4 answers

Reduce Multiple Objects into One

Let's say I have an array of objects: [ { category: 'Category A', max: 10, min: 12 }, { category: 'Category B', max: 2, min: 1 }, { category: 'Category C', max:…
LuisDemn
  • 19
  • 4