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.
2
votes
Accepted
Computing the subtotal of all items on their property criteria: qty * price
is there any efficient way to do this in JavaScript?
I compared the for, forEach and reduce efficiency using console.time utility. And found that for is faster among the three for the same data. …
12
votes
Accepted
Palindrome checker in JavaScript
return str === reversedStr;
See Which equals operator (== vs ===) should be used in JavaScript comparisons? …
0
votes
Optimization of Javascript Function swapping out images for gifs
Number of functions 2n
You're creating two functions per image one to handle mouseenter event and other to handle mouseout event. If you look at the mouseenter handler of all the images, you'll notic …
2
votes
Accepted
array_diff in JavaScript
You can use Array#filter to get elements from array which are not present in other array.
var a = [2, 4, 8, 16, 32],
b = [2, 4, 32, 64, 128, 256];
// Define custom method on Array prototype
…
2
votes
Accepted
Removing duplicates from multiple arrays at once
Create a function on Array.prototype that'll accept an array and filter the array by checking if the element is in the other array.
// Define a function on Array prototype
Array.prototype.arrayDiff = …
1
vote
Accepted
Displaying text on button click
</span>
<span class="cover_letter_suggestion_add_button">
<button class="btn btn-xs rounded btn-primary">{% trans "Add" %}</button>
</span>
</div>
Javascript
Use common class to bind …
5
votes
A function to split an string of alphabets and numbers into arrays and sort them respectively
You can use RegEx to extract the sequence of alphabets or numbers.
To match alphabets/number, use character class in Regular expression as below
/[A-Z]+|[0-9]+/
to match all occurrences, use g(glob …
14
votes
Accepted
Basic JavaScript template engine using replace, match and RegExp
JavaScript
match => map => n * replace
In the three functions, you're first using match to get the matches then iterating over it and using replace inside it. This is not at all necessary. … Which equals operator (== vs ===) should be used in JavaScript comparisons?
For default values, || can be used instead of ternary.
The default value for _array should be [] instead of {}. …
2
votes
Accepted
Showing the current view-position within the web page
Here are some improvements:
Use IIFE.
This will make the variables defined inside it private thus avoid cluttering globals
Passing window and document objects will make it available in current sco …
1
vote
Accepted
jQuery for revealing secondary menu
Here's the equivalent code.
// Check if this element has the specified class
if ($(this).hasClass('primary-item-a')) {
// If there are one or more visible `ul`s
if ($parent_li.siblings().fin …
4
votes
Accepted
Make an image appear on scroll event
It's easy and safe than using css() to change the styles of element from JavaScript. This also keep separation of concerns. … See Which equals operator (== vs ===) should be used in JavaScript comparisons?
if (pastScroll === currentScroll) {
Chaining. jQuery provides feature to chain multiple calls on same elements. …
2
votes
Accepted
Any field change in form, disable button, and activate another
Core JavaScript has dataset property that allows access to data attributes. … The relation between HTML element-JavaScript handler is reduced from many to many to many to one. …
1
vote
Get average of each nested array in dynamic object
See JavaScript property access: dot notation vs. brackets?
Typo
In the object, the keys for movie name has typo. It should be movieName. … ECMAScript 2015
If the target environment support latest version of JavaScript, use the features provided by it.
Complete code:
if (! …
2
votes
Accepted
Project Euler LCM of 1..20, with some guesswork
The below formula can be used to get the LCM of two numbers. See Reduction by the greatest common divisor section in Wikipedia
a * b
lcm(a, b) = ―――――――――――
gcd(a, b)
GC …
3
votes
Accepted
Remove specific CSS rules from WYSIWYG text
See Javascript regex multiline flag doesn't work
With these changes the regex will become
/(a:link,\s*span\.MsoHyperlink|a:visited,\s*span\.MsoHyperlinkFollowed)[\s\S]*?}/gi
Here's demo. …