Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
JavaScript is a versatile, high-level programming language. It is the programming language in all browsers.and can be used for back-end programming with node.js. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too.
15
votes
Trapping Rain Water
Reviewing complexity
So far only one answer has addressed the complexity issue, and is a considerable improvement over your solution. As the existing answers have addressed code style I will stick to …
12
votes
Accepted
Function to build a string based on the recursion depth
I did toy with the following version but for me it is not as elegant due to the forced flow unique to Javascript that will put those from other languages out of joint. …
11
votes
Convert a string like 4h53m12s to a total number of seconds in JavaScript
Named Capture Groups
JavaScript RegExp has named capture groups that can make life a lot simpler when dealing with complicated RegExp. … seconds"));
function log(...data) {
document.body.appendChild(
Object.assign(
document.createElement("div"), {textContent: data.join(" ")}
)
)
}
BTW in Javascript …
10
votes
Stack Implementation in JavaScript
Encapsulate
The object Stack should protect its state as it is easy to add and remove items via the exposed referenced Stack.items, or if Stack.length were to be set some erroneous value eg myStack.l …
10
votes
Accepted
Improving particle performance in P5.js
When you splice Javascript has to move every item above the splice point down one. And if the array size falls below half its size, it will dump the reserved space for GC to clean up. … Then if you add one item javascript will ask for all that memory back. This can be very costly. …
10
votes
Accepted
Rotate an N × N matrix 90 degrees clockwise
Are you up to date?
There is really not much to the problem and there are a variety of solutions.
It is also hard to know what the interviews are looking for. For some it is knowledge of latest lang …
9
votes
Accepted
Checks user level and limit the data before saving it to mongoDB
I am not a mongoDB user but is there not some type of validation API, not sure if it can be used on schemes. If it can then maybe that is the better option for your code.
The Question
It have bee …
9
votes
Count all vowels in string
Sᴀᴍ Onᴇᴌᴀ answer has the right idea for small strings, but can be improved by using a Set to hold the vowels rather than an array. This reduces the overhead of Array.includes which will iterate each c …
8
votes
Accepted
Reverse Integer
To get the sign of a number use Math.sign
-JavaScript numbers are doubles but when you use bitwise operations on them they are converted to 32 bit signed integers. … JavaScript can handle hex 0x10 === 16, decimal 10 === 10, octal 010 === 8 and binary 0b10 === 2 (oh and BIG ints 10n === 10) Hex makes realy easy to remember the lowest and highest int for a given size …
8
votes
Restructuring JSON to create a new JSON where properties are grouped according to similar va...
JavaScript convention is to use camelCase for names rather than snake_case. … JavaScript has several ways to use hash maps (Object property names, Map, Set, WeakMap, and WeakSet)
In this case you can use Map to group by unique item values Map(key, {date: key}) creates a hash for …
8
votes
Accepted
Snake on a Plane
Use function statements "function funcName(){ ...code... }" rather than function expressions var funcName = function(){ ...code... }
Add "use strict" to the first line of the JavaScript file or script … As with all variable declarations care must be taken to ensure uniqueness of the name across the scope of the document and javascript context. …
8
votes
Accepted
Sort a list of pairs representing an acyclic, partial automorphism
Code style
Use constants for variables that do not change. Eg const sortedArray = [];
Don't include the type in the name, Eg const sortedArray = []; can be Eg const sorted = [];
The default paramet …
8
votes
Accepted
Generate an HTML table using JavaScript from an array of objects
Use the DOM APIs
For performance avoid adding markup (HTML) to the page via JavaScript. The DOM APIs are much faster and can be abstracted to make more readable code (DOM APIs are very verbose). …
8
votes
Accepted
Compute count of unique words using ES6 sets
Two problems
Your code has two problems.
It does not remove punctuation from the words resulting in the same words not matching. Eg text1 has 12 unique words not 13. You count dolor and dolor. as …
8
votes
another Tic-Tac-Toe Game
In Javascript game loops are driven by a timer event that is synced with the display hardware to ensure (if possible) that the animation is presented to the display at a consistent frame rate (generally …