The Stack Overflow podcast is back! Listen to an interview with our new CEO.

New answers tagged

2

Convenience typedefs Consider adding convenience typedef declarations on your structs and enums, i.e. struct Value { // ... }; becomes typedef struct ValueTag { // ... } Value; You've already done this with Stack, though I recommend renaming the tag: typedef struct TagStack { struct Value *array; size_t used; size_t size; } Stack; ...


2

Poor memory usage Javascript has managed memory. That means it does all the hard work of allocating and releasing memory, which is great (managing memory manually is a real pain). But this useful feature comes with a down sides... Managed memory environments are inherently slow, Managed memory environments encourage very poor memory usage patterns ...


3

Since you mentioned morelinq in your question. It does have the Batch method which is similar. It's an IEnumerable<IEnumerable<TSource>> instead of IEnumerable<TSource[]> but if you look at the source code it's actually an IEnumerable of an array but you can't count on that as it's an implementation detail. The only issue I see with ...


3

If this wasn't a programming challenge with restricted modules, I would suggest using pandas. It has a rolling windowed median implemented, so it is quite straight forward (just have to be careful not to have an off-by-one error with the shift): import pandas as pd def activityNotifications(expenditure, d): df = pd.DataFrame(expenditure) return (df....


9

There are not much to review, so to answer your questions: It's a good extension if you can see it useful in more than one place. It makes sense. I can't see anything else to consider - a null check on the predicate maybe? If the exception thrown by the predicate when @this is null is good enough for you, don't bother further. I don't see why the ...


4

The code is mostly readable and clear: the variable names are descriptive (for the most part - x is a little unclear) there is good use of const and let instead of var Some of the lines are a little lengthy - the longest line appears to be 117 characters long (excluding indentation): newIntervals[newIntervals.length - 1][1] = Math.max(newIntervals[...


3

These two functions look quite sufficient to solve the task. I will say that the functional solution will likely be slower, not only because it is functional but also because of the call to .flat() and iterating over twice as many elements. Correct me if this is incorrect, but the call to .flat() could be removed if the call to .every() was changed to a ...


2

one other idea is to add chunked to Array (source: HackingWithSwift): import UIKit extension Array { func chunked(into size: Int) -> [[Element]] { return stride(from: 0, to: count, by: size).map { Array(self[$0 ..< Swift.min($0 + size, count)]) } } } struct Point { let x: Int let y: Int } struct Line { ...


Top 50 recent answers are included