Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
42 views

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 ...
Arnaw Gundawar's user avatar
-3 votes
1 answer
105 views

Description: I've been playing around with Codingames today, and came across this problem in a Clash of Code. Problem: Given a word, output the sum of the word's index according to it's place in the ...
Beca_1923's user avatar
0 votes
1 answer
76 views

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 ...
aw_codes's user avatar
0 votes
1 answer
93 views

I have a simple php array that looks like this & I am looping over it to assign its keys as properties to an stdClass object & its values as the values of those keys. My code looks like this $...
Richard's user avatar
  • 561
1 vote
0 answers
47 views

I've got a two-dimensional array: $array = [ ['property', 'group1', 'was', 'added'], ['property', 'ouch', 'was', 'removed'], ['property', 'ouch', ...
Artem Pokhiliuk's user avatar
0 votes
1 answer
119 views

I have been going through online study on a resource I quite liked till this very moment. The problem is they want my perfectly working array_reduce function is written "in immutable style". ...
Artem Pokhiliuk's user avatar
0 votes
1 answer
243 views

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, ...
Angel's user avatar
  • 989
-1 votes
4 answers
2k views

I have the following array of array of objects that is a result of a CloudWatch query using AWS-SDK-V3 JS: const respCW = [ [ { field: '@timestamp', value: '2022-10-25 15:30:36.685' }, { ...
IgorAlves's user avatar
  • 5,580
1 vote
1 answer
70 views

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. ...
DanNg's user avatar
  • 70
0 votes
3 answers
95 views

I am getting data from API structured like this: interface ProductModel { prod_id: string, brand: string, ... } interface OrderModel { order_id: string, prod_id: string, ... } ...
Emili Bellot Pulido's user avatar
0 votes
1 answer
1k views

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 ...
CRIS's user avatar
  • 356
0 votes
0 answers
23 views

I need to write an hook that fetch the URL query parameters to return an object of strictly type T export function useQueryParams<T>(): [ T, ({ key, value }: { key: keyof T; value: string }) ...
Antonio Santoro's user avatar
1 vote
1 answer
870 views

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 (...
ashleedawg's user avatar
  • 21.9k
3 votes
6 answers
14k views

How can I remove duplicates from an array someArray like below based on the name property given the condition that if name is the same for two elements but for one them the type is new, the original ...
Smarajit's user avatar
  • 173
0 votes
5 answers
2k views

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 ...
iNeeR's user avatar
  • 9
0 votes
0 answers
21 views

So I was going through the MDN docs on the .reduce method in JavaScript and I was having a hard time understanding what is going on with the accumulator (acc). I was expecting the accumulator to ...
corn's user avatar
  • 9
0 votes
1 answer
311 views

I need to run multiple timer one after another with pause. Input for timer comes from the array which contains set of times. I did something with reduce method. But could not break early the reduce ...
Shiva C's user avatar
  • 30
0 votes
4 answers
94 views

I have an array in Javascript and I need to combine objects if they have equal reminder.date const tasks = [ { id: 1, title: "call Tom", reminders: { date: "2022-02-01", ...
Ruslan Almukhanov's user avatar
2 votes
3 answers
597 views

I am trying to perform operation on array that is described in topic. What I've done already - group by common property + map data of each item to desired format. It was achieved by using reduce + map ...
D.Wasilewski's user avatar
0 votes
1 answer
325 views

I have this source array(): $source[] [ ["user_id": 1, "item_id": 991, "quantity": 100], ["user_id": 1, "item_id": 992, "quantity":...
Bo. Ga.'s user avatar
  • 148
2 votes
2 answers
1k views

I have 3 label that can receive input when button clicked and then i need sum from the third input value the code kinda work but instead of getting the sum of the third input it instead it looks like ...
Suriadi Chandra's user avatar
1 vote
1 answer
289 views

I have array of dates grouped by day and I want to group dates by time start and end and subtract last value - first value. The time start and end are also in an array. Data array: const data = [ { ...
Dev M's user avatar
  • 1,719
1 vote
2 answers
106 views

I have the array of dates and I want to group dates by year and subtract the last value - the first value. for example, I have the following array: const data = [ { x: "2021-10-17T14:38:45.540Z&...
Dev M's user avatar
  • 1,719
0 votes
2 answers
637 views

I want to aggregate array of object into single object with each object having distinct value. But My code is not giving me desired output. Can someone please help me? My Input : [{ "...
Samira's user avatar
  • 81
0 votes
1 answer
73 views

What is the best way to refactor(ise) an array / array of objects ? I was thinking of using array.reduce, but could not figure out a solution. for example, transform this array : const carsInput = ...
midnight's user avatar
0 votes
2 answers
193 views

How to shrink an array if two consecutive numbers in an array are equal then remove one and increment other Example 1: int a[6]={2,2,3,4,4,4}; // Output: 6 Example 2: int b[7]={1,2,2,2,4,2,4}; // ...
Jahnavi Dunaka's user avatar
-2 votes
1 answer
957 views

I am trying to replicate the function below using Array.reduce private getCount = (str, value) => { var count = 0; const everything = ['Key1', 'Key2', 'Key3', 'Key4', 'Key5']; for (let i = 0; i &...
LearnToImprove's user avatar
0 votes
2 answers
72 views

If have two arrays (content & ids) which i need to combine in one array (combined). First Array: let content = [ { "Name": "Max Mustermann" }, { "Name": "Berta Beispiel" }, { "Name": "...
Robin's user avatar
  • 111
0 votes
1 answer
539 views

I am working with users data inside array and I want to print user data inside html table without using foreach loop but alternative of that using array_walk() <?php $users=$this->db->get('...
Anonymous's user avatar
  • 1,094
1 vote
1 answer
48 views

i have an array like that in $_POST var; but need know that in some cases the array is a hugge multilevel from json: array ( 'idprocess' => 'f-gen-dato1', 'idform' => 'f-gen-dato2', ) OR: ...
user avatar
1 vote
1 answer
285 views

Please explain the code and elaborate what is running behind the code. I'm confused with if part if(! acc[key]). does it mean if key not in acc and set key with value array and jump out of if ...
daneillone's user avatar
2 votes
5 answers
237 views

I have an array of objects as mentioned below. const inputArray =[ { name: "Energy", quantity: [ { qval: "100 ", unit: "unit1" }, { qval: "200 ", ...
Shah's user avatar
  • 79
2 votes
1 answer
546 views

I want to make condition out of the following array, but it does not give my expected result because it does not run the second condition. $arr = [ [ 472 => [ 'EL' =&...
the thinker's user avatar
-1 votes
3 answers
572 views

I have a array with following values.I am trying to create a new array using array php array functions and trying to max avoid foreach. The key we are using for new array is "status" and depending on ...
Mail4Coder's user avatar
1 vote
3 answers
3k views

I have an array that looks like this: let movies = [ 'terminator.1', 'terminator.2', 'terminator.3', 'harry-potter.1', 'harry-potter.3', 'harry-potter.2', 'star-wars.1' ] and I would ...
OmarAguinaga's user avatar
3 votes
5 answers
1k views

I have need to calculate the sum of the deep elements foreach first level element. Sample 3-level array: [ 1 => [ 'A' => ['AA' => 3, 'AB' => 5], 'B' => ['BA' => 2]...
payket's user avatar
  • 137
-1 votes
3 answers
4k views

Array ( [0] => Array ( [package] => LTE_15AGB [value] => Array ( [0] => 52690 [1] => 24700 ...
Arebhy Sridaran's user avatar
0 votes
4 answers
524 views

How can I use array.reduce to change the way the content of the array is. I don't want to do any math on the content. Orinal array: var myArray = [ {id:1, name:'name01', value:11}, {id:2, ...
Somename's user avatar
  • 3,444
1 vote
3 answers
2k views

I have an array of StdClass Objects and want to return the "partner_code" with the minimum value for key "price". So for this example I would like to return partner_code "AC" as it is the partner with ...
Michael Alterio's user avatar
0 votes
5 answers
2k views

I have an array [ { price: 10 }, { price: 10 }, { price: 10 }, { price: 10 }, { price: 20 }, { price: 20 }, ] and I want it transformed into [ { numElements: 4, price: 10 }, { ...
Jamgreen's user avatar
  • 11.2k
1 vote
1 answer
5k views

I have an array like this $filter_array = Array ( [0] => Array ( [fv_id] => 1 [fv_value] => Red [filter_id] => 1 ...
phpnerd's user avatar
  • 926
1 vote
1 answer
481 views

I want to have that variable $total[$i] giving the result of the following function: $total[$i] = (array_reduce((array_map(function($x, $y) { return $x * $y; }, $corp_resp[$i], $...
Christophe Costa's user avatar
0 votes
1 answer
3k views

I have that code where i want to multiply corp_resp for corp_resp_template and sum dynamically. $total = (array_reduce((array_map(function($x, $y) { return $x * $y; }, $corp_resp, $...
Christophe Costa's user avatar
1 vote
2 answers
62 views

I am trying to merge 5 associative arrays which having different keys. This is the result after using array merge on 5 arrays array_merge($bucketExlData1, $bucketExlData2, $bucketExlData3, $...
Vijay Kumar Prajapat's user avatar
13 votes
18 answers
15k views

After implementing database queries, I am getting the multi-dimensional array below. Two Dimensional Array Array ( [0] => Array ( [t1] => test1 ) [1] => ...
Karan Adhikari's user avatar
2 votes
1 answer
2k views

Evolving from Javascript, spliced FileReader for large files with Promises, how?, which showed me how a Promise can also resolve a function, now I am stuck with the same but inside an Array.reduce ...
GWorking's user avatar
  • 4,381
-5 votes
1 answer
100 views

var developers = [ { name: "Joe", age: 23, overallLevel: "high", date: "Aug 14, 2015" }, { name: "Sue", age: 28, overallLevel: "advanced", date: "Aug 11, 2015" }, { name: "Jon", age: 32, overallLevel: ...
Saily Jadhav's user avatar
3 votes
2 answers
4k views

var developers = [ { name: "Joe", age: 23 ,overallLevel: "high"}, { name: "Sue", age: 28 ,overallLevel: "advanced" }, { name: "Jon", age: 32 ,overallLevel: "high" }, { name: "Bob", age:...
Saily Jadhav's user avatar
4 votes
1 answer
1k views

Why does the array_reduce() method work differently when adding and multiplying? When I add the array values below, the code produces the expected result: 15. But when I multiply, it returns: 0. Same ...
shmuli's user avatar
  • 5,212
1 vote
1 answer
1k views

I have below $test array Array ( [0] => Array ( [quantity] => 3 [stock_id] => _PHONE ) [1] => Array ( [...
SonDang's user avatar
  • 1,607