7

For any of the following suggestions, please do profile them to test the performance difference. Performance is likely to vary across multiple browser implementations of the JavaScript interpretation engine. Rather than a loop for getNumBits, try Math.floor(Math.log(n)/LN_2) - or maybe trunc instead of floor - where LN_2 is precomputed as Math.log(2). Try to ...


4

Here's my proposal: function sortObjectByValue (obj) { const map = new Map() Object.entries(obj) .sort((a, b) => obj[b][1] - obj[a][1]) .forEach(([key, value]) => { map.set(key, value) }); return map; } You don't need to create a sorted object unless you want to use it, I understand that you are using a Map so that you can ...


2

Use events and callbacks to react to things as they happen instead of repeatedly checking for changes. You can use the .then function to do whatever needs to be done once the data is received. You can learn about the <video> element events here: https://www.w3schools.com/tags/ref_av_dom.asp


2

There is a more efficient way to implement getNumBits (compared to @Reinderien's answer), if you use some bitwise magic: function getNumBits(x){ x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; x -= (x >> 1) & 0x55555555; x = ((x >> 2) & 0x33333333) + (x & 0x33333333); ...


2

Sadly, the PHP part is neither efficient nor optimal. Apart from already mentioned issues, your function does too much work, which makes it non-reusable and which bloats your code in general. Remember the rule of thumb: each unit of code should mind its own business. While your function interacts with a client through $_POST and echo, connects to a database, ...


1

I already gave many suggestions in my review of your previous question. I see that some of the advice has been incorporated - e.g. "use strict", using the spread operator, etc. Yet it seems some of the advice hasn't been used (e.g. variables starting with $, using jQuery more, etc.) but I won't lose sleep about those. I suggest avoiding use of var ...


1

Private methods There isn't one de-facto convention about private method naming. For example, the Google JS Style guide states: 6.2.3 Method names Method names are written in lowerCamelCase. Names for @private methods must end with a trailing underscore.1 While the AirBnB style guide states: • 23.4 Do not use trailing or leading underscores. eslint: no-...


1

From a short review; the tilescale is 16 which is a great value to multiply or divide with, so x = x/tilescale; z = z/tilescale; can become x = x >> 4; //Divide by 16 (tilescale) z = z >> 4; //Divide by 16 (tilescale) this does mean that changing the tilescale can become a performance drag (like in real games) So are 256 and 4, so return(...


1

I don't think I can review all of that, but here are some thoughts to your questions and some general remarks. const/let I would guess this is simply that your programming style colliding with the trend in JavaScript towards functional programming where mutability is an anti-pattern and generally avoided. The first step to using const is to avoid reusing ...


1

From a quick review; You could host your templates as separate HTML files, retrievable with a fetch You would have the overhead of extra http calls HTML tooling might be worse for HTML templates/snippets I agree with your boss, html code does not belong in a database template should be const let template = document.getElementById("vacancyTemplate&...


1

A few points, most of these I have applied to your code here: https://stackblitz.com/edit/so-in-mem-db?file=index.js Potential use of Map and O(1) time The javascript objects you are currently using are de-facto dictionaries, so it is unlikely you will gain anything here. Unnecessary use of !! You have used this frequently in your code, in all the places I ...


1

From a short review; You probably want to encapsulate if(matrix === null || matrix.length === 0) into an isValidMatrix function for re-use I would drop the whole i/j thing and go for variables named after row and col I would collect all the rows and columns with a 0 in one set of loops, and then clear the matrix based on the collected rows and columns in ...


1

It would be great if the code could be simplified using dynamic imports. I haven't tried this myself but if the image names could be put into an array then something like the following might work, where the exported images are set as properties on an object that can be exported. When this SO answer to Create a loop to import files dynamically in React was ...


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