58 questions
0 votes
0 answers
41 views
Optimised Javascript/TS code to find the total quantity for each base item, when more than 1 cart item can be pointing to the same base item
I need the most efficient way to calculate the total quantity for each base item by going through a list of cart items and sum up the quantities for all cart items having the same base item. My ...
0 votes
1 answer
74 views
having an issue with Array.reduce(). I have somewhat correct output. But I can't figure out the rest
Here are the instructions: Pretend that there is no Array.filter() method. Use Array.reduce() to filter out only the objects from the provided array with a price property of 10 or over. Pretend ...
1 vote
0 answers
47 views
how to pass a value into a next iteration of array_reduce in immutable style?
I've got a two-dimensional array: $array = [ ['property', 'group1', 'was', 'added'], ['property', 'ouch', 'was', 'removed'], ['property', 'ouch', ...
0 votes
1 answer
242 views
Laravel/PHP: Add another condition in array_reduce function
I have multidimensional array and I want to sum all the same value with a certain condition. Here's what my array looks like $input_taxes = [ [ "tax_account_id" => 65, ...
1 vote
1 answer
68 views
How to get the wanted result using reduce javascript?
I'm trying to understand how the reduce method work. The groupBy function only return object that is grouped by category. How do I get the wanted result below? I have tried many ways but none works. ...
0 votes
1 answer
1k views
TypeScript - Array reduce return object with specific type/interface
I'm creating a generic function that gets properties from an object using array.reduce. I would like the return type to only return the type of properties extracted from the original object type ...
1 vote
1 answer
868 views
Count bottom-level elements in nested object of objects of arrays
I have an "object of objects of arrays" and I simply need to get the total count of elements in the "bottom level" arrays ...so with the example below, I need to return 19 (...
0 votes
5 answers
2k views
I need to remove duplicate products in an Array and sum their quantity in JavaScript
In the program, I fetch arrays of products from orders via API. The array contains a list with products that are duplicated. I need to remove the duplicate products in the array and sum their ...