New answers tagged

0

This is undefined behavior: namespace std { template <class T> void swap(range_iterator<T>& lhs, range_iterator<T>& rhs) { lhs.swap(rhs); } template <class T1, class T2, class U1, class U2> void swap(range_step_iterator<T1, T2>& lhs, range_step_iterator<U1, U2>& rhs) { ...


2

From java 8 it is available in the String class the method join that achieves the same result of your method stringConcat so instead of: String k = stringConcat(achat.getCodSociete(), achat.getCodService(), achat.getNumCompte(), achat.getCodCommande()); You can use String.join with "" delimiter: String k = String.join("", achat.getCodSociete(), achat....


1

AggByA: baseline two-pass method presented by the OP. AggByB: one-pass method using Aggregate suggested by @PeterTaylor AggByC: one-pass method implemented by hand I left most error handling to the reader since I personally don't believe it is necessary, or even helpful, in something this abstracted. If the caller wants extra safety then they can easily add ...


3

I think in general MinBy and MaxBy are useful but handling all the null cases might be tricky, and indeed it is seeing the repeated logic and two similar loops. For this reason I also think that it'd be easier if we do not handle them at all but let the user decide what he wants to do with them and implement both simply with OrderBy(Descending).First() ...


6

public static TSource ArgBy<TSource, TKey>( MinBy and MaxBy are very intelligible names, but ArgBy doesn't say much to me. Really this is a specialised Aggregate (and I wonder whether an implementation using Aggregate might be simpler - or, indeed, whether the existence of Aggregate makes ArgBy unnecessary). Func<(TKey Current, TKey ...


2

General things Please use two lines for template class declarations: template<class T> class my_list { // Do this template<class T> class my_list { // In nearly all other cases I am fine with the // { being on the same line. But class and function // declarations you just need the ...


5

(Note: Martin York posted an answer when this answer is halfway done. The already written part will be left as is, but I try to avoid duplicating content after that. Make sure you read that answer as well!) General These are general suggestions: First of all, please write the declaration of a template class on two lines and use more spaces — ...


1

I agree with the advice in dfhwze's answer. Because ecmascript-6 features like arrow functions are used, for...of loops could be used to simplify the loop syntax. And instead of pushing values into questions and incorrect using i, Array.push() could be used. I see that getData() is called at the end of completionScreen(), which is called at the end of ...


2

Implementing both Iterable and Iterator at the same time is a bit weird choice and while the API documentation for Iterator makes no claims about the implementation, I think most people would assume that subsequent calls to iterator() return a different object each time and those objects, if used for reading only, do not interfere with each other.


2

Ok, so, per @markspace, you've made this a lot more complicated than it has to be. In Python, yield is being used to save the state of a function. In Java, you'd just use a stateful object that executes the desired function. I'm pretty sure you could either create a FibonacciIterator or a FibonacciSupplier and meet your requirements. In either case, every ...


1

Some notes on readability I will focus on method getQuestion. The first thing I noticed is that your indentation is very confusing. You start with an outer loop, and it looks it contains only 2 statements. However, the entire remaining method body is part of that loop. This pop in indentation introduced at var characters should never have been there. for(...


2

Prologue I have a DateTime class (my own, not System.DateTime) You could have just pasted the code for that class. Since you are asking a question about sorting, and your DateTime class implements IComparable, its content could have been pivotal for a proper review. Parodos Here is a method that takes a List<DateTime> and sorts it: You have ...


1

Convert key-value objects to array The way you traverse your objects is convoluted. Calling Object.keys() and Object.values() all over the place like for(let i=0; i<Object.keys(markObtained).length; i++) and const data = Object.values(markObtained)[i]; can easily be avoided if you transform your input into an array. // input = your original students ...


3

Honestly, that really doesn't look that bad to me. It's probably what I would come out with after a first go - not that I'm some sort of Rust guru. That being said, I'll discuss below a couple of things that you might like better. It'd also be worth running Clippy over the program and having a look at what it says. Not everyone likes everything Clippy ...


1

Review Note that I'm using arrow notation which was not available back then. But that does not impact the issues addresses in this review. Method overload resolution allows an explicitly implemented interface method to call the implicitly one: IEnumerator IEnumerable.GetEnumerator() { return new NListEnumerator(this); } IEnumerator IEnumerable....


Top 50 recent answers are included