Skip to main content

All Questions

Filter by
Sorted by
Tagged with
1 vote
1 answer
61 views

Unexpected results working on Array of Integers

While going through and re-factoring some Java code I wrote a while back for Project-Euler. I ran into an issue with integer overflow where the answer was too large to contain in type int. This was ...
tijko's user avatar
  • 8,332
0 votes
1 answer
167 views

Most Pythonic way to handle exception caused by functools.reduce when the iterable yields no elements?

Python's functools.reduce throws an exception when the iterable passed to it yields no elements. Here's how I currently use it: some_list = [] # empty list should be permissible functools.reduce( ...
user2138149's user avatar
  • 17.9k
0 votes
0 answers
52 views

Rewriting loop unflattening array as reduce [duplicate]

I have the below loop: while (flatArray.length > 0) nestedArray.push(nestedArray.splice(0, ROW_SIZE)); It meant to convert a flat array into a two-level nested array [a row/column -like setup]. ...
Igor Shmukler's user avatar
0 votes
0 answers
59 views

Deep reduce(): using functions with multiple return values

I was able to figure how to apply different reduce-funcs at every level of hierarchy in a list-of-lists structure. def deep_reduce(funs, lol): def isi(a): return isinstance(a, (list,tuple,types....
sten's user avatar
  • 7,486
0 votes
2 answers
771 views

chain lodash _.groupby() with reduce

Starting with an array similar to this: const arr = [ {id: "id_0", owner: "owner_0", state: "accepted"}, {id: "id_1", owner: "owner_1", state: &...
natew's user avatar
  • 1
-3 votes
2 answers
50 views

Please why is my code not working,do I need to install any library

Recently started functional programming and all explanations of the pipe and compose using reduce which I have seen are very sketchy. const x = 4 const add2 = x + 2 const multiplyBy5 = x * 5 const ...
Steve purpose's user avatar
1 vote
2 answers
2k views

How to use 'reduce' function to filter and display products in cart

I am trying to train myself with Javascript and am a bit confused with reduce and would appreciate some guidance in understanding it. I've done a lot of research and have arrived at a stage where some ...
Alim Bolar's user avatar
1 vote
2 answers
4k views

Kotlin - How to convert a list of objects into a single one after map operation?

I'm trying to wrap my head around map and reduce operations in Kotlin. At least, I guess it's reduce what I'm trying to do. Let's say that I have a class called Car that takes any number (varargs ...
Allan's user avatar
  • 55
0 votes
1 answer
70 views

What is the reason array is available inside reduce(), map(), etc.?

In the following example, we have access to the array as numbers and arr. It seems more in line with functional programming to use the internal variable arr but what is an explicit reason why we ...
Edward Tanguay's user avatar
0 votes
1 answer
111 views

Is a reduction to a non-scalar value ever useful/used?

Normally, I will see a reduction that reduces some sequence into a value. Just using the most basic example, let's do a sum and count reduction: # sum >>> reduce(lambda x,y: x+y, [1,2,3]) # 6 ...
David542's user avatar
  • 111k
4 votes
1 answer
1k views

How to use stream reduce with different types?

I have a stream of values with type One and I want to reduce them to a value of type, Sum. (it's not integers, just for example). And, I have a BiFunction summator which returns Sum (Sum sum = ...
Maksim Maltsev's user avatar
1 vote
1 answer
108 views

How to write reduce function with memo of arbitrary type

I am trying to write a simple histogram program that takes a stream of unknown (very large) length, integers only, and bins them up. My problem doesn't relate to binning so we can assume that the ...
qqq's user avatar
  • 1,430
0 votes
1 answer
77 views

Looping Over Async Calls by Emulating .reduce() with async/await

Variables & Functions used in the code: const fakeAPI = (delay, value) => new Promise(resolve => setTimeout(() => resolve(value), delay)); const useResult = x => console.log(new Date(...
afyonkes's user avatar
  • 155
0 votes
2 answers
144 views

Filter elements of object composed by objects by value, vanilla JS

I have this object with some values; among them a byKey object with some other objects: const myObject = { byKey: { 1: { id: "One", getIt: true, }, 2: { id: &...
Emille C.'s user avatar
  • 612
1 vote
3 answers
86 views

Transform array using reduce (property undefined)

I want to transform an array to regrouping all cities for the same country. I have an array of Object locations = [ { cities: ["Paris"] country: "France" }, { cities: ["...
Abdelrhany Mdjr's user avatar

15 30 50 per page
1
2 3 4 5
11