why someone just write Overly Complex 2 times
I don't know what format you originally received this information in, but it looks like there are 4 "tags" applied to your application:
Overly Complex Solution
Strange Coding Conventions
Hard to Understand
With someone having modified the first one to include some extra information:
I have little to add to what Pod said.
There is nothing wrong with compact code. Your code could be very efficient, and there is clearly a lot of effort in it, but I agree readability could be improved. Indeed the small details count, even whitespace is important in code.
The important takeaways:
Good code should have a natural flow and should be visually ...
There's certainly nothing wrong with using a cookie for this, but it is, alternatively, entirely possible to monitor open tabs on the client side, using localStorage.
The example below listens for page load and unload events:
when a page is loaded, a new entry is added to localStorage
when a page is unloaded, the last entry is removed from localStorage
More concise code
First, you can compute weightSum using a reduce() function instead. I am not sure if there is any particular performance benefit to this or not, but it does allow you to put everything on one line if you like that sort of thing.
const weightSum = weights.reduce((sum, weight) => sum + weight, 0);
Similarly, in newer versions of ...
If you want step by step visualization then you'll need to break up your function into sections: init, step and finalize.
init is everything before the main while loop.
step is the while loop body