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

I have a few other minor thoughts, but the big one is: rather than building the lookup dictionary on each call, since it's the same static and read-only data, presumably forever, make it a class-level member and don't pass it around: private static readonly IReadOnlyDictionary<char, char[]> _LettersMap = new Dictionary<char, char[]> { ...


6

This looks like a decent recursive implementation. So, this is mainly about style and readability. First, I would like to talk about two things which are really hard and could use some improvement here, naming and consistency of semantic levels. Then I have some more miscellaneous comments. Naming Generally, the naming is not too bad, but some of the ...


6

Review LetterCombinations returns an IList<string> but I see no reason to return a modifiable collection. Consider returning IEnumerable<string> instead. A method's name should be a verb. Change LetterCombinations to GetLetterCombinations, FindLetterCombinations or PermutateLetterCombinations. You did good by creating a private function that ...


5

I'd suggest the following changes: Use a loop instead of recursion Use for/of instead of .forEach() push a single value instead of using an array with one element in it cache the lowest value so far so you don't have to constantly refetch it on every comparison Use a temporary array for the sort so the function is non-destructive to the source array (...


5

Review findMinimum means to me that you find the minimum value in an array of items. Since your function returns the index instead, call it indexOfMinimum. Prefer the use of const over let if you only assign a variable once: let minIndex = findMinimum(toSort); -> const minIndex = findMinimum(toSort);. Use arrow notation to write more compact functions: ...


5

Style I suggest you check PEP0008 https://www.python.org/dev/peps/pep-0008/ the official Python style guide while writing your code and the following goes accordingly: Docstrings: Python Docstring is the documentation string which is string literal, and it occurs in the class, module, function or method definition, and it is written as a first statement. ...


4

As pointed out by @bullseye, the itertools library provides combinations(). If you are trying to learn how to implement your own version, here is a simple recursive version: def combinations(seq, r): """returns a list of all r-length combinations of the elements of seq.""" if len(seq) == r: # only one combination return [seq] ...


3

To answer the question from the comment on RoToRa's answer: Thanks! I wonder if there is any way to do this by using, for example, just the Java 8 Stream API or something similar, to have it in just one line of code. Using the Java Stream API Assuming the following Entry class: public class Entry { final String key; final List<Entry> ...


2

The function is a bit repetitive, as both cases (iterating over sub array vs individual elements) check if the element is undefined and if the return array includes that value. That could potentially be abstracted to a separate function or simplified. It appears that the following line: var index = props[level]; Could be moved outside of the forEach ...


2

First off, I'm assuming the call of the method flatEntriesMap is wrong and it should be a recursive call to flatTree. (EDIT: Source code has been corrected.) Then you should reconsider the name, especially considering the confusion before your edit: You are not flatting the tree, but retrieving its leaves. To get rid of the side effect, you simply make the ...


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; ...


1

docstrings and comments There are lots of formulas in the drawing code, like: + SPC * (N-n) + tkn * n + RIGHT + tkn * n + SPC * (N-n) How did you arrive at those. How would they change if you wanted to do some other kind of animation? I would add a ASCII art drawing of a puzzle being solved, annotated with the dimensions and formulas. Hidden interfaces ...


1

Good things: all lines terminated with a semi-comon strict equality used when checking for objects I would suggest using const by default since none of the variables/functions get reassigned. If you determine reassignment is necessary then use let. This will help avoid accidental re-assignment. And is the variable naming oclone Hungarian notation? If so, ...


Only top voted, non community-wiki answers of a minimum length are eligible