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

New answers tagged

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


0

Counter intuitive? Infinite loops. The function is an iterator so this may not be undesired or potentially fatal for the application. However some inputs would make one wonder about the callers intent. numrange(0, 100, 0); // will endlessly return 0 numrange(0, 100, -1); // will return 0, -1, -2, ... Infinity numrange(0, -100, 1); // will return 0, 1, 2, ....


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


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


1

General feedback This code looks decent, though as Andrew's answer points out many of the names are misleading. My biggest complaint is that semi-colons aren't used to terminate lines. While they are only required after a handful of statements, it could lead to errors if somehow whitespace got removed. It is a good habit to default to terminating lines with ...


2

UI Instead of a number input, a range input could be used - with the minimum value being zero and the maximum value being half of the lesser of the height and width - in this case 88 pixels (i.e. 175px / 2). With such an input there is no need to validate user input to ensure non-numeric characters are entered. With the current interface, the event handler ...


2

PHP Constants The first five variables in db.php could be declared as constants since they shouldn't be changed: define('DB_HOST', '127.0.0.1'); define('DB_USER', ''); define('DB_PASS, ''); define('DB_NAME, 'doodle'); define('DB_CHARSET', 'utf8mb4'); And notice the prefix DB_ was added to those names to specify that those values pertain to the database. ...


3

In JavaScript using exceptions to communicate standard logic information is rather bad. Exceptions are bulky and slow (some browsers can not optimise code containing try blocks). Your handling of errors will also mask real errors and thus let serious problems slip by while developing the code. When you use exceptions always check the error in the catch to ...


6

I would limit my review to db.php file only. First of all, I see you made use of some of my advises already, probably visited some of my articles. Sadly, not all recommendations are followed, but that's OK, we'll review them. Connection The connection part is simply OK, nothing to review Structure Regarding the structure, I would say this file is a bit ...


3

const stack = new Array() Use the literal notation ([]) instead. Here's an answer on Stack Overflow that elaborates why you should do that instead of new Array(). const duplicate = () => { try { const dup = pop(); push(dup); push(dup); } catch(e) { throw new Error(e); } }; The rule of thumb ...


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


0

This is okay for as a start. However you are missing the two classes Bus and Ambulance. Few comments: (1) You are using this._variableName pattern - although not wrong this is a bit redundant way to express yourself. Historically _variableName or m_variableName comes from C++ to indicate member variables. However, this.variableName already means that this ...


2

If you wish to keep your implementation scheme, I only have one large critique: Names are important Your naming scheme should allow a 3rd party to understand your code from a cursory glance. You have a lot of sneaky implementations tucked into your functions that aren't expressed in your naming convention. All of your operations are stateful, which is ...


4

The main suggestion I have is to take the values from sitesToBlock and put them in the @match metadata key instead of detecting when to update the document content. There is an extensive guide about match patterns here. With this approach there should not be any need to wait for the DOM to be loaded and check if the URL contains elements in sitesToBlock, ...


Top 50 recent answers are included