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.
5
votes
Accepted
Copy part of array in javascript
You're on the right track trying slice. Here's an example of using it with no loops required.
Initialisation
You could initialise newArray with an element directly in the declaration, removing the n …
2
votes
Accepted
Avoid re-initialize values in javascript
You could remove the need for your xAxis variable through using the index when mapping:
vm.pnLreportingPlotData.push(plotModel.map(function (o, i) {
return { x: i + 1, y: o.PnLreporting }
}
vm.var …
2
votes
Refactor Jquery .text () function
selectorToResponse[selector]
$header.text(response)
}
}
}
Notes
Above uses strict equality comparison (===) instead of abstract equality comparison (==). https://developer.mozilla.org/en/docs/Web/JavaScript …
4
votes
Accepted
Logging a user in and creating a session
Potential improvements
generateToken(email, password) {
let user, session;
return module.exports.destroyInactive()
.then(() => users.checkPassword(email, password, sharedSecret))
.then(_ …
1
vote
Sequence program (FizzBuzz-like)
ES6 solution:
// If using require and have lodash
const { range } = require('lodash');
// If not, define our own. Does not default start=0 but isn't needed in this example
const range = (start, end) …
2
votes
Chaining promises into a callback
Removing Promise constructor wrappers
As @Peilonrayz mentioned in his comment, we can return the promises directly instead of wrapping them in Promise constructors.
From the MDN: Promise docs:
T …
2
votes
Photo rating function
There's a few things you can do and different approaches depending on your personal preference. You could:
Extract the cases to pure functions
Extracting the logic to methods could help with readabi …
2
votes
Coin Change Kata in ImmutableJS
Flambino's answer really hits the nail on the head. However, I'll still provide this solution just for a syntax comparison.
This solution differs in a few areas but the logic is almost identical. Th …
1
vote
Accepted
ESLint rule for Jasmine/Protractor
Your naming of variables is good, they're mostly descriptive and easy to follow.
You could use reverse conditional to reduce the cyclomatic code complexity, doing that your code would look something …
3
votes
Adding and Deleting in ES6 Javascript Alone
You are already using quite a lot of ES6 features (const, arrow functions, Array.prototype.find, etc)
Here's a few more places you could use some ES6 features:
Array.prototype.findIndex / Array.prot …
9
votes
Accepted
Hamming distance between numbers in JavaScript
Your solution is almost identical to the example on the wiki page where you can see hardware optimisations if supported, though the example does not apply to JavaScript. …
4
votes
Accepted
Instantaneous validation of form field length
Ternary operator
You could use the ternary operator for your first if-else case:
warning.style.display = input.value.length >= 1 && input.value.length <= 3 ? 'block' : 'none';
Now, this is a bit le …
3
votes
Accepted
Particle text directive
See clean-code-javascript for some of the advice applied to JavaScript. … I recommend Airbnb's JavaScript Style Guide as a good starting point. …