New answers tagged

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


0

I'm pretty sure the js convention is still to prefix "private" stuff with an underscore. class QuickSort { sort(a) {...} _sort(a, lo, hi) {...} ...} The only other thing that sticks out to me is your use of ++ and -- in the while loops. While perfectly idiomatic, I think it would express the logic better to move both conditionals together in ...


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

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


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


0

As was already mentioned in the comments, a switch statement could be used to clean up the sets of if statements. Another option would be to abstract the similar callback functions passed to .reduce()- perhaps using partially applied functions to accept parameters - e.g. the minimum values in conditions like currentChamp.getCost() <= 3. It seems like let ...


0

Note- the review below only pertains to the code in the post. "Code that's not included can not be reviewed."1 Overall I would say this code is well-written. Variables are declared with const and let appropriately. It has good documentation - especially for each method- although example usage is tough to find. One possible change you could consider ...


1

Return Value The method addUser returns false for all negative cases. Below it is possible to see that it does not return true for the positive case.. instead it returns nothing which leads to an undefined: else { $('#loadingDiv').show(); $.post('process/editUser.php', {uobj:uobj}, function(data) { var modal = "#addUserModal"; $('#...


1

I see you removed the calls to $('#loadingDiv').show(); from the many conditional blocks and moved that before the call to the AJAX call - I was going to suggest that. I see the ecmascript-6 features like the Class syntax are used, so other ES-6 features could be used - like the short-hand syntax - i.e. on this line: $.post('process/editUser.php', {uobj:...


5

It doesn't look like this has been suggested yet but you can use object destructuring so you don't have to repeat blog a couple of times. computed: { getfilteredData() { const term = this.search.toLowerCase() return this.blogs.filter(({ name, category }) => { return name.toLowerCase().includes(term) || category.toLowerCase().includes(...


3

As already mentioned, the code is ok, but if you want to make it cleaner by removing code duplication, you can introduce local variables and helper functions: getfilteredData() { const term = this.search.toLowerCase(); const isMatched = str => str.toLowerCase().includes(term); return this.blogs.filter(blog => isMatched(blog.name) || isMatched(...


6

Another way is to create an array from name and category and combine some method with include: const result = blogs.filter(blog => [blog.name, blog.category].some(s => s.toLowerCase().includes(searchRow.toLowerCase())) ); It would be very convenient to scale your method by adding into array just necessary property. Let me show an example: let ...


12

One improvement would be factoring out the repeated call to this.search.toLowerCase() and storing the result in a block-scoped constant so it: doesn't need to be calculated on every call to .includes() for each iteration of filter() can decrease the length of each line where that value is used That may be a small optimization but it is in line with the D.R....


7

It is really hard to say, but at least for me, your code is fine. It seems readable and has no issues. Perhaps if you want to change the style and make it more "canonical", you could write instead: computed: { getfilteredData() { return this.blogs.filter(blog => blog.name.toLowerCase().includes(this.search.toLowerCase()) || ...


1

I think a functional style is a good choice. Provided you have the right sort of algorithmic complexity, I don't think you should worry about performance until it shows itself to be necessary. That being said, I think there's room for improvement if you're aiming to be functional, or at least doing things in another way that has other benefits. An idea of ...


1

To start, I must say that I wish I was writing JS like this in 2016. I have only recently been becoming acquainted with the newer features ecmascript-6 has to offer. After looking at the other answers to the post you mentioned I would have suggested they consider using destructuring assignment, but I doubt it would help for your code. For readability it can ...


2

I assume, that you are exercising formatting and handling time correctly, so I won't mention, that you could do it in a "oneliner" using the existing api (for the options see here): let options = { hour12: true, hour: "2-digit", minute: "2-digit", second: "2-digit" }; function showTime() { ...


1

It's looking good and it works. A few remarks within the code function showTime() { const date = new Date(); let hours = date.getHours(); let minutes = date.getMinutes(); let seconds = date.getSeconds(); let session = (hours < 12) ? "AM" : "PM"; // You can stringify the minutes and seconds using a template string, // for ...


2

Some repeated code, i.e. (<X> < 10) ? '0' + <X> : <X>;, this can be factored into a utility in order to be more DRY. Using string::padStart you can ensure a string of minimum length is returned, padding the beginning of the string until it achieves the length. The padStart() method pads the current string with another string (multiple ...


2

1 You are repeating condition ? '0' + integer : integer 3 times. This can be reduced with const zeroPad = (num, places) => String(num).padStart(places, '0') and doing hours = zeroPad(hours, 2); minutes = zeroPad(minutes, 2); seconds = zeroPad(seconds, 2); The 2 is now a repeated magic number and you may wish to store it in a variable with a ...


2

Not an O(n) MMMR library There are a lot unnecessary inefficiency on that code. For big data, it makes a lot difference. The current version, time complexity-wise... $$\text{ mean() and mode() are }O(n)$$. $$\text{range() and median() are } O(n .log(n))$$. All could be implemented in average time complexity O(n). Not only that, checking if the list is ...


Top 50 recent answers are included