reduce Questions

2

Solved

Say I have a sequence of items and I want to perform a reduce operation via myReducer function (whatever it is). If my items are in an array (say myArray), it's easy: myArray.reduce(myReducer); ...
Gavelkind asked 23/11, 2018 at 16:19

5

Solved

This problem has been bugging me for a while now and I can't seem to find an answer in web. Is it possible to use Array reduce method starting from a certain index? simple example var studentGra...
Nard asked 27/1, 2016 at 9:55

7

Solved

I am trying to solve "A very big sum" challenge on Hacker Rank: https://www.hackerrank.com/challenges/a-very-big-sum/problem In there I have to sum all the numbers in the array given so I...
Eyeleteer asked 29/5, 2020 at 15:58

18

Solved

How can I break the iteration of reduce() method? for: for (var i = Things.length - 1; i >= 0; i--) { if(Things[i] <= 0){ break; } }; reduce() Things.reduce(function(memo, current){ if(c...
Jehad asked 22/3, 2016 at 0:56

25

Solved

How do I find the arithmetic mean of a list in Python? For example: [1, 2, 3, 4] ⟶ 2.5
Leathery asked 27/1, 2012 at 20:58

5

My code has an array of elements as follows: element: { fromX: { id: ... } , toX: { id: ... } } Requirement is to pull all the fromX ids into one array, and all toX ids into other. There are a ...
Fingertip asked 15/1, 2019 at 14:52

5

Solved

Is there an analog for reduce for a pandas Series? For example, the analog for map is pd.Series.apply, but I can't find any analog for reduce. My application is, I have a pandas Series of list...
Conventionalism asked 26/1, 2016 at 0:18

13

Solved

How would one take a JavaScript array of objects, such as objArr = [ {key:"Mon Sep 23 2013 00:00:00 GMT-0400", val:42}, {key:"Mon Sep 24 2013 00:00:00 GMT-0400", val:78}, {ke...
Crim asked 7/10, 2013 at 19:45

2

Solved

Swift 3 Trying to write a generic array extension that gets all indexes of items that DON'T equal value example let arr: [String] = ["Empty", "Empty", "Full", "Empty", "Full"] let result: [Int...
Amargo asked 21/12, 2016 at 5:48

7

Solved

I was wondering what would be the best way to split an array into two different arrays using JavaScript, but to keep it in the realms of functional programming. Let's say that the two arrays shoul...
Ruwenzori asked 9/8, 2016 at 21:20

14

Solved

Assuming an array of objects as follows: const listOfTags = [ {id: 1, label: "Hello", color: "red", sorting: 0}, {id: 2, label: "World", color: "green", sorting: 1}, {id: 3, label: "Hello", col...
Hera asked 29/11, 2018 at 15:54

7

Solved

Code speaks better than language, so: ['a', 'b', 'c'].reduce((accumulator, value) => accumulator.concat(value), []); The code is very silly and returns a copied Array... TS complains on conc...

5

Is there any way to map/reduce/filter/etc a Set in JavaScript or will I have to write my own? Here's some sensible Set.prototype extensions Set.prototype.map = function map(f) { var newSet = new...
Depositary asked 20/10, 2015 at 10:50

7

Solved

I am pretty confused with both functions fold() and reduce() in Kotlin, can anyone give me a concrete example that distinguishes both of them?
Congruence asked 8/6, 2017 at 7:35

4

Solved

i am figuring out a way to get the sum of values of classes which are contained in an array. My setup is as follows: class CustomClass { var value: Int? init(value: Int) { self.value = value }...
Choe asked 15/2, 2019 at 16:59

4

Solved

simple example, want to return an array of arrays. For each name in 'peeps' I want to push an array with the word 'hello' into the accumulator. const peeps = ['sally', 'nick', 'dave']; return pee...
Attentive asked 27/1, 2017 at 9:23

1

Solved

In Cuda C++, I have a big array Arr of integers, and a function F: int -> int. I want to find the first index of some items in Arr that makes F maximal. How can I write a kernel that always keep...
Rumery asked 6/12, 2022 at 23:1

7

Solved

I'm using Python 3.2. Tried this: xor = lambda x,y: (x+y)%2 l = reduce(xor, [1,2,3,4]) And got the following error: l = reduce(xor, [1,2,3,4]) NameError: name 'reduce' is not defined Tried pr...
Peay asked 31/12, 2011 at 16:25

23

Solved

Say I want to sum a.x for each element in arr. arr = [ { x: 1 }, { x: 2 }, { x: 4 } ]; arr.reduce(function(a, b){ return a.x + b.x; }); // => NaN I have cause to believe that a.x is undefined a...
Frontogenesis asked 20/4, 2011 at 14:31

11

Solved

Seem to be having some issues incorporating async/await with .reduce(), like so: const data = await bodies.reduce(async(accum, current, index) => { const methodName = methods[index] const met...
Orjonikidze asked 20/12, 2016 at 13:26

4

I see many posts/questions addressing this issue, so I assume it is not trivial. I am quite a beginner, looking for a more elegant solution. I need to reduce this kind of array containing 1-minute ...
Blacktail asked 3/9, 2022 at 17:23

4

Solved

Is this intended behavior? I would expect an empty array to be returned here. JavaScript let arr = [1]; console.log(arr.splice(0, 1)) Console 1
Illfated asked 8/3, 2017 at 20:18

5

Solved

Trying to learn F# but got confused when trying to distinguish between fold and reduce. Fold seems to do the same thing but takes an extra parameter. Is there a legitimate reason for these two func...
Coricoriaceous asked 29/1, 2012 at 19:2

6

Solved

I found a very useful function reduce, and I'm using it, but I'm not sure if I understand it properly. Can anyone help me to understand this function? Example: var arr = [ 1, 2, 3, 4, 5, 6 ]; arr.r...
Bute asked 28/10, 2015 at 13:27

4

Solved

I've been using map and reduce over some objects and arrays which have been working well so far, however I'm having trouble with one array. Example of data here: var arr = [ [ { "id": 6501511, ...
Tripinnate asked 4/8, 2017 at 18:20

© 2022 - 2024 — McMap. All rights reserved.