New answers tagged

1 vote

Sum up nested array of objects based on keys

I'm going to make an up-front assumption that many of the truthy checks you're doing (e.g. ... || 0) is simply to check if a value is undefined or not, and you don'...
user avatar
1 vote
Accepted

Sum up nested array of objects based on keys

You are returning a new object in each iteration inside the reducers, when you could use just one object for the tallies (see below). The handling of undefined values suggest to me that the underlying ...
user avatar
  • 600
5 votes

Sum two vectors in x86 assembly

A bug Using ebx is OK, but like esi and edi it is a callee-save register, so you should save ...
user avatar
  • 6,359
0 votes

Sum up nested array of objects based on keys

I found it useful to ensure that the input data was sanitised to remove the possibility of undefined values before further processing. Much of the verbosity of the code was to do with checking for ...
user avatar
1 vote

Porting PHP's array_push to Python

Some points to supplement @FMc's answer (though we'll put aside for the moment its excellent advice against mutation): The way you compute keys when extending dictionaries can be tidied with ...
user avatar
  • 533
4 votes

Porting PHP's array_push to Python

The list case. As noted in a comment, you can simplify to this: array.extend(args) The dict case. It looks like the goal is to find the max integer key, if any, ...
user avatar
  • 9,475
2 votes

Deepest pit of an array

function deepest_pit(B) { The JavaScript style guide here indicates that camelCase is recommended for functions. JavaScript is ...
user avatar
6 votes

Deepest pit of an array

Overall, reading this code, my reaction is "huh?". It looks like a bunch of gibberish at first (and second) glance. There are no english words. I would not want to maintain this code after ...
user avatar
0 votes

Populate array using elements from four source arrays

Shouldn't that be about the same as ...
-1 votes

LeetCode: House Robber II C#

Here is another version of a solution ...
user avatar
  • 5,249
0 votes
Accepted

Populate array using elements from four source arrays

Unsure how many rows are in PricingDatesArr, but I would start by moving ...
user avatar
1 vote

Suggestions for improvement for generic array and map functions in Go 1.18

Right, I've had a closer look at the Map type you posted here (don't know why, but that one piqued my interest more than the list). There's quite a lot to unpack ...
user avatar
1 vote

Merge sort in PHP 5

It appears that you have quite a bit of experience with mergesort in various programming languages. While it may obviously be deemed a bit tangential to the purpose of StackOverflow I can’t help but ...
user avatar
1 vote

VBA - Compare & Consolidate Dynamic Arrays

A well-known code development aphorism is "Make it work. Make it right. Make it fast" (Kent Beck). The most nebulous statement here is "Make it Right". I would propose that ...
user avatar
  • 953
1 vote
Accepted

Practicing with array

Advice 1 Judging from the method name mostLikedPost, you expect the most liked post and not its number of likes, so you must have ...
user avatar
  • 25.3k
2 votes

Why is this tensor contraction so slow and how can I make it faster?

Let's look at just out[0, i, j, k] for now. The inner loop looks like u += A[l]*B[i, j, l]*C[0, i, l, k]. What is its memory ...
user avatar
0 votes

VBA - Compare & Consolidate Dynamic Arrays

The structure of your code would suggest that your chances of being recognised as a developer are practically zero. You have many functions encapsulated in a single method. Split your Method into ...
user avatar
  • 625

Top 50 recent answers are included