4

You seem to ignore two facts. The client clock can be out of sync with the server clock. The transport of the request from client to server takes more then zero time. Both these cases mean that no matter how hard you try on the client side, there is always a chance that the server will evaluate the token as expired during its processing. What you should ...


3

Welcome to Code Review! As I already mentioned in comments, epoch values can be treated as normal numerals, without having to involve momentjs or other external libraries. In js, you can get current epoch value in milliseconds accuracy using Date.now(). The value in token is with seconds accuracy. It is only a factor of 1000. Rewrite /** The token object ...


3

DRYing The separate numeric-indexed IDs are used only to get to their children .cart-quantity-input elements, so you can just select those elements directly instead and remove the IDs. When you have to select something else in the same row, first use: const $row = $(this).closest('.cart-row'); and you'll get to the row, from which you can, with .find, ...


3

Bug Reading the details of the problem there is nothing regarding the max "number of ways". For an array of 100,000 items there are a max of 5000050000 "number of ways" which is much greater than 1000000000 in the test you perform that breaks out of the loop. if(numberOfWays > 1000000000) { If you consider the set of all possible ...


2

Implementation Review Ten years ago there were typically users that would commonly use IE and code like this that creates elements, adds event handlers to those elements and then removes those elements had the possibility to leak memory. While that may not be an issue anymore it is something to consider. A simpler approach would use event delegation to ...


1

Functions Always write functions. Even if its just an experiment or example code, writing the code as a function provides you with a better representation of the problem at hand. As a function the code is easier to read and understand defining the code as a verb, can often provide a simpler solution, keeps the namespace (scope) clean, and is portable for......


1

When you want to find a particular matching value in a data structure, using Array.prototype.find is usually the right way to go. It's complicated by the fact that the condition involves the value of the object, but you want the key of the object to be found, so to iterate over the keys and values at once, use Object.entries. It'll give you an array of [key, ...


1

It is difficult to tell "which one is better". As Jan mentioned in a comment: "tell which one is better" - what does "better" mean? performance? code readability? ... ? The notion of better is subjective. I am drawn to the first solution as it uses the fewest lines, though readability suffers because the lines are quite long ...


1

Here are some suggestions and a version that tries to illustrate most of these points. 1. Separation of concerns There should be some separation between the code that handles (i) the display and (ii) the underlying game logic and representation of the board. People often use design patterns like model-view-controller. A classic way of separating them would ...


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