New answers tagged javascript
1
vote
Accepted
Three efficient JavaScript functions that converge to pi extremely fast
In terms of more precision, I can't really help there... But, in terms of general code styling and performance, I'd be happy to give some pointers. This is good code, but slightly inconsistent (which ...
1
vote
Sum up nested array of objects based on keys
I'm going to make an up-front assumption that many of the truthy checks you're doing (e.g. ... || 0) is simply to check if a value is undefined or not, and you don'...
1
vote
Accepted
Sum up nested array of objects based on keys
You are returning a new object in each iteration inside the reducers, when you could use just one object for the tallies (see below). The handling of undefined values suggest to me that the underlying ...
3
votes
Slug Generator in Javascript
Nice work! Here are some suggestions:
Input variable doesn't change, make it constant
I wouldn't imagine that you would want to reassign nameValue to something else,...
1
vote
Rock, paper, and scissors game
TL;DR
Quality code is easy to reason. Whilst you are in the midst of development you will have a good mental model of what the various parts do, but if you come back to this later, or someone else ...
0
votes
Sum up nested array of objects based on keys
I found it useful to ensure that the input data was sanitised to remove the possibility of undefined values before further processing. Much of the verbosity of the code was to do with checking for ...
1
vote
Calculate the value of PI in JS
There's no need to recalculate the factorials and powers from scratch each time around the loop. Remember the last values and just multiply to get the next value.
Approximate idea (untested, and by a ...
0
votes
Accepted
Add and delete books into this bookshelf vanilla javascript project
Just to start, the code snippet is not working so I can't really tell what your piece of software looks like upfront. But based on the code you shared, there are some things that I think can be ...
2
votes
Deepest pit of an array
function deepest_pit(B) {
The JavaScript style guide here indicates that camelCase is recommended for functions. JavaScript is ...
6
votes
Deepest pit of an array
Overall, reading this code, my reaction is "huh?". It looks like a bunch of gibberish at first (and second) glance. There are no english words. I would not want to maintain this code after ...
1
vote
Destructuring an object in JS
I think the two previous answers offer improvements, but I'd like to throw another suggestion into the mix :)
When dealing with JSON like this, the fragility from the deep lookups send shivers down my ...
1
vote
Destructuring an object in JS
A super short review;
data seems to be a global variable with a super generic name, that's a bad idea
Destructuring is cool, but personally, this feels like too ...
1
vote
Destructuring an object in JS
Using an arrow function as inline function does not make the code very readable.
Why assign variables if they are only used once?
...
1
vote
Accepted
Typescript simple observable state and web component
It looks like you have learned a lot from it. I want to concentrate on your points you've listed on what you're looking for in terms of this review.
Style
Probably the two biggest things that grabs my ...
2
votes
Find first and last matches on a sorted list
Binary search
This should be a binary search as that is the expected algorithm. Why? because the array is sorted. Your function does not take advantage of the fact that the elements are sorted. ...
-1
votes
1
vote
Accepted
Asynchronous recursive function for generating a unique Id
Over engineered
This code is over engineered.
It is not asynchronous (nothing is pausing execution)
The id is too complex for the domain of books (ids in ...
3
votes
Script becomes too big
There are ways to improve your code, let's start by taking a look at the first few lines:
...
1
vote
comparing two names using fuzzy
I guess this code was taken a bit out of context, and might reside in a different form elsewhere. I've noticed a few things here, so here is my review:
Everything resides in global space and the ...
1
vote
0
votes
-1
votes
New Year Chaos JavaScript, needs to be sped up
The input array is: [1 2 5 3 7 8 6 4], which means that:
5 jumps 2 positions, so increment counter by 2 (c = 2)
7 jumps 2 positions, so increment counter by 2 (c = 4)
8 jumps 2 positions, so ...
1
vote
Estimating the total production count from a few random serial numbers
The review comments are inline after ///. A summary of the review follows the code
...
0
votes
Find first and last matches on a sorted list
A short review;
I prefer list over arr, because I prefer fully spelled out words above abbreviations, but I like obvious one ...
0
votes
Find first and last matches on a sorted list
You answer seems fine. Don't worry about how other people have solved the same problem.
The break/continue logic is not bad GIVEN the question, but you should definitely comment in your code what the ...
0
votes
Find first and last matches on a sorted list
Here is a revised, simpler version of your code.
...
1
vote
Accepted
JavaScript function that generates Fibonacci like sequences of given order
Your algorithm for an n element Fibbonacci series order k is O(N*K) Your JavaScript implementation may be inefficient. I revised your algorithm to become O(N). I revised your JavaScript implementation ...
-1
votes
Accepted
Replace the src of an image for each link in a nav menu
You can have some util methods to generate based on date.
...
3
votes
Tic-Tac-Toe vanilla JS Pseudo OOP
Answering Questions
How to implement a MVC pattern? Right now, the state and HTML elements are global variables, but I think this could be stored in state and UI classes Also, I'm having troubles ...
0
votes
A simple JavaScript function that does prime factorization
Taking a square root is a very slow operation, so it's a bad idea to do it for every iteration of the loop. Rather, you should only update the limit whenever n ...
2
votes
Accepted
FizzBuzz in JavaScript (node.js), my first JavaScript program
A short review;
special is not an evocative name, maybe divisors?
special is polluting the ...
2
votes
FizzBuzz in JavaScript (node.js), my first JavaScript program
Wikipedia: Fizz buzz
Programming
Fizz buzz (often spelled FizzBuzz in this context) has been used as an interview screening device for computer programmers. Writing a program to output the first 100 ...
1
vote
Tic-Tac-Toe vanilla JS Pseudo OOP
It's good for what it is, and the end result looks nice.
I want to suggest you look into Typescript for type safety and readability, a framework like React/Vue/Angular/Svelte to avoid having to do DOM ...
0
votes
Accepted
Is my approach for Palindrome right or is there a better way to do it?
From a short review;
palindrom01 does too much
it finds the input
it determines whether the input is a palindrome
it prints to the console
These could be 3 ...
0
votes
Update button onclick using Jquery
No, not even close.
Unfortunately your question is lacking context, specifically what the types of the variables ddCount and type...
1
vote
Accepted
Javascript grabbing sum
Reduce
You could have used Array.reduce
function sum(...rest) {
return rest.reduce((n, val) => n + val, 0);
}
Or as
<...
1
vote
How to optimize clz count leading zeroes manual implementation?
What about using a hashmap instead? Have tested this with the given code and it looks like it works
...
3
votes
Accepted
User registration and login service using JWT
Nice work, the code looks good!
Couple of comments-
With ES6 syntax, if you're returning an object with a property that is coming from a variable of the same name:
...
2
votes
Categorise amount into "small", "medium" and "large"
Test on max only
Or min only, but both is not necessary. Here, I'm coding for "max":
...
Top 50 recent answers are included
Related Tags
javascript × 9626jquery × 2321
html × 1039
node.js × 908
performance × 840
beginner × 677
ecmascript-6 × 641
css × 596
algorithm × 479
object-oriented × 408
array × 392
angular.js × 356
dom × 355
react.js × 343
ajax × 300
programming-challenge × 285
functional-programming × 281
html5 × 261
json × 227
promise × 224
game × 222
event-handling × 218
strings × 216
animation × 216
datetime × 192