4,418 questions
Best practices
0
votes
5
replies
91
views
Option Array, locating and returning array with correct criteria
I have an object db that has one field containing SKU's that correspond to another object that contains different venues.
db.SKU = [1002,1005,1001,1008,1007];
I then have another object listing the ...
9
votes
1
answer
152
views
How to remove character differences from multiple strings [duplicate]
Let's say I have a bunch of product strings that could vary slightly in format, e.g.:
Super red Megaman T-shirt
Super Megaman blue T-shirt
Super black Megaman T-shirt
Super Megaman T-shirt - ...
0
votes
0
answers
42
views
What does this reduce() function do in counting elements from an array? [duplicate]
I'm trying to understand how the reduce() function works in this example:
const fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple'];
const count = fruits.reduce((tally, fruit) => {
...
-3
votes
1
answer
102
views
Excel - Dynamic array FILTER to return ARRAY for Stock Portfolio Cost Tracking
I'm updating a tracking spreadsheet for a stock portfolio and would like to dynamically pull the holdings of the portfolio at specific time periods so that I can view the holdings at any point in time,...
1
vote
2
answers
104
views
Implementing a factorial function in Scala
I'm working out of Scala for the Impatient (3rd Edition). (I'm not doing this for a class.). I'm trying to implement a factorial function using to and reduceLeft without a loop or recursion. This ...
-3
votes
2
answers
69
views
Add key/value to dict in map method
I have this code:
results = "[ { user_name: 'User 1',
email: '[email protected]',
userid: 'HJ10092',
event_type: 'download',
country: 'Venezuela',
doc_type: 'mspowerpoint',
...
-3
votes
1
answer
83
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 {
/...
2
votes
0
answers
43
views
NVIDIA webinar on parallel reduction gridsize
In the last example of Mark Harris' webinar I don't understand the indexing before the parallel reduction part. In "Reduction #6" the gridSize/number of dispatches was ceil[N (the size of ...
0
votes
0
answers
28
views
Flatten Date Sequence with an attached Value in Google Sheets (Without the use of Macros)
This is a similar question that was posted before but with a little expansion to the problem.
The original post was this link:
Create flatten dates sequence in Google Sheets in one column (without ...
3
votes
1
answer
89
views
OpenMP reduce on large heap array cause segment fault
When I try to reduce a large heap array with OpenMP reduction, it segment fault:
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
...
0
votes
1
answer
92
views
Inject behavior when last element is used before referencing accumulator
I am a a bit confused by some of the behavior of the of the inject (alias reduce) command in Ruby
Background
For any array, the second element (referenced after the accumulator) reflects the last ...
-1
votes
2
answers
82
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",...
0
votes
2
answers
89
views
Label the row according to the source
I want to importrange from Spreadsheet OLD with several tabs/sheets into Spreadsheet NEW. What i want to do is to import values from SheetA and Sheet B.
First column: vstack(importrange(SheetA!A5:A),...
5
votes
3
answers
112
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
2
answers
67
views
React transform data using reduce
I need to transform the following structure using React.
export const bodyRows = [
{
row: [{ cell: "Name" }, { cell: "Allan, Trent" }, { cell: "Smith, Nathan" }, { ...
0
votes
1
answer
31
views
App producing 2 messages for only 1 input
I'm trying to debug a problem in our production Kafka Streams app. The (simplified) topology looks something like this
builder.stream("input").groupByKey().reduce(
(agg, val) -> "...
3
votes
1
answer
313
views
CUB reduce_by_key
Thrust has the thrust::reduce_by_key algorithm which works well for a problem of mine. I wanted to try to use CUB for finer control of memory and streams as well as interaction with my own kernels, ...
2
votes
3
answers
335
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
234
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 ...
0
votes
1
answer
136
views
JQ Cannot iterate over null
I am trying to create a jq that is dynamic in returning data.
User Story: I have data with many fields and not named like I want. I want to be able to based on the data and schema transform the data.
...
0
votes
2
answers
141
views
pandas - merge multiple dataframe with reduce
I saw many post talk about use reduce to merge multiple dataframe. I try below code, it works with three dataframes, if it greater than three, tan, error reported:
pandas.errors.MergeError: Passing '...
2
votes
0
answers
73
views
Scala Seq.reduceLeft does not update the accumulator value?
I have the following code snippet to combine a Seq of (DataFrame, BloomFilter) tuples. The DFs are in chronological order, and the goal is to union and deduplicate all the DFs while always selecting ...
0
votes
1
answer
86
views
finding max from Vec<Enum> - using reduce()?
I'm sure there is a better way to do this, but I do not know how to extract structure from Enum during reduce(). Assume ALL enums are identical in vector (but prob. solution needs to handle if this is ...
0
votes
0
answers
91
views
Summation problem when using OpenMP to parrallelize C++ code
I'm trying to use OpenMP with the following C++ code:
double delta(10);
const bool parallel = true;
...
delta = 0;
#pragma omp parallel for collapse(3) reduction(+:delta) if(parallel)
for (unsigned ...
0
votes
3
answers
101
views
Accessing a class member inside another another class from a Python Lambda expression
I cannot understand why I cannot reference the integer member of the nested class in the lambda. The following code demonstrates the failure. The same reference is used in the print prior to the ...
0
votes
1
answer
162
views
Reduce an Image in C
Hello fellow programmers. I'm new to the forum so please bear with me.
What I am trying to achieve is taking a loaded image from file(e.g. background wallpaper image 4000x2250) and scale it down to ...
1
vote
0
answers
67
views
How to use `reduce` with `and` in MIT-Scheme? [duplicate]
Recently when I self-learnt MIT 6.5151 course, I first read CS 61AS Unit 0 as the preparation. Then I have read SICP 1 to 2.1 (with related lecture notes) as ps0 requires (also read 2.2.1 as CS 61A ...
2
votes
9
answers
506
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
134
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)
},
{
...
3
votes
2
answers
136
views
How to make a `functools.reduce` implementation that looks similarly as `Reduce` in R?
Here is an R example of using Reduce
x <- c(1, 2, 2, 4, 10, 5, 5, 7)
Reduce(\(a, b) if (tail(a, 1) != b) c(a, b) else a, x) # equivalent to `rle(x)$values`
The code above is to sort out the ...
0
votes
1
answer
37
views
Performance when using window function use influxDB 2.7.6
I am using influxdb 2.7.6, and created a measurement called cgm_glucose_history. I added a tag called device_sn, a field called glucose, and a field called device_time to record the exact time when ...
4
votes
3
answers
121
views
Computationally efficient alternative to row-wise apply on a list with same-length vectors
I have a list of same-length vectors that I need to run different statistical functions on per vector element across the list. I know I can do this with apply by creating a data frame first and then ...
1
vote
2
answers
70
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
2
answers
80
views
Is there a better way to create an array with multiple queries based on a dynamic range without having blank lines?
I have an invoicing summary and reporting spreadsheet and am trying to create a dynamic summary for each client (number of clients can change) where each invoice is listed per client, with a sum total ...
0
votes
0
answers
58
views
Type 'T[keyof T]' cannot be used to index type 'T[]'
I'm trying to write this recursion function that will pivot an array of object so I am trying to use generics. The code actually works perfectly, but I cannot figure out how to make typescript happy. ...
0
votes
0
answers
56
views
Javascript reduce returns empty object in async function
I have an Angular app and I am getting the contents of a json file from Google Drive. The contents is an array of 1011 customers that I want to transform into an object. However the reduce function ...
2
votes
2
answers
496
views
Data manipulation in google sheets with arrayformula and lambda helpers
i've got a quite complex situation to solve with google sheets. I already solved it in a very unelegant way, and I would need your help to understand why other solutions I tried failed, and maybe to ...
3
votes
5
answers
162
views
Clojure reduce not producing expected results
Why does the first reduce not work but the second does? The order of the comparisons should be the same...
(reduce (fn [{:keys [minimum maximum]} new-number]
{:minimum (if (and minimum (< ...
0
votes
2
answers
87
views
Is there a way to simplify the multiselect query in the google sheets?
The source file contains 17k to 20k rows.
I'm struggling with the speed of calculating, the sheet is unresponsive for 60+ seconds. There are 14 executions of this function per sheet, and 6 sheets ...
0
votes
0
answers
80
views
Skewness and kurtosis for image processing
While running python map reducing code to calculate skewness and kurtosis values i am unable to get output:
Code
import os
from mrjob.job import MRJob
from scipy.stats import skew, kurtosis
import ...
1
vote
1
answer
99
views
Is it possible to store large data arrays in a single cell for future reference in Google Sheets?
The current formula returns 2 columns and multiple rows. I want to store the result in a single "data cell" for future reference and post-processing.
Is it possible to make sure that the ...
1
vote
1
answer
65
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 ...
0
votes
0
answers
86
views
Trouble With Reduce Function in Google Sheets
I have a sheet of tools that I have organized that I called "DATABASE" which is essentially just a list of my tools that are organized by their location and ID number:
I also have a ...
0
votes
1
answer
33
views
Creating Column of seats from a single line description in Google Sheets
we are booking a training and we are trying to convert a description of what seats we have into a columnn list so we can automatically allocate our students to a class.
Eg the the description of the ...
1
vote
1
answer
295
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 |
|---------------------------|----------------|----------------|
|...
0
votes
2
answers
51
views
How to Sum Duplicate Items in a Two Dimensional Array using Apps Script?
How would you take an array such as this:
arr1 = [[1150-500101-1000005530, 2750.0],
[1150-500101-1000005530, 275.0],
[1150-500101-1000008371, 825.0],
[1150-500101-...
-1
votes
1
answer
188
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
68
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 ...
1
vote
0
answers
345
views
How to bind using BindingReducer to subset of the childstate using tca
I am struggling with tca 'BindingReducer' and 'onChangeOf'.
I want to bind childState from ParentState, especially 'subset of the childState' changes.
Maybe there are several solutions, but i think '...
0
votes
2
answers
430
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 ...