39
votes
Accepted
Count all vowels in string
An alternative route is to use string.replace() and Regular Expressions to strip everything but the vowels from the string. Then count the length of the resulting ...
28
votes
Count all vowels in string
I'm just wondering if there's an easier way to solve this problem without the big blocky code in the if statement.
Well, you could put all of those in an array:
<...
21
votes
Setting flags to show three buttons
You could take an object and check if the action exists. If so, take the value as key for assignment.
...
16
votes
Accepted
Convert minutes portion of time to decimal
Use const instead of let to declare variables if the value doesn't change.
You are executing ...
14
votes
Accepted
Array duplicate removal for duplicates exceeding `N`-number
As you expected, there is a much simpler way to do this.
Create a map where the keys are the numbers in the array and the value is the number of times each number appears in the array.
Filter the ...
14
votes
Accepted
Using async / await with dynamic import() for ES6 modules
Approach 2 does not work because accoring to MDN:
import '/modules/my-module.js';
Is how you import a module for Import a ...
13
votes
Stack Exchange review queue notifications
I don't see much benefit to the enum. The Notification.permission string (or the return value of requestPermission()) is already ...
13
votes
Vue.js search functionality
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 ...
12
votes
Accepted
Reformatting a date from YYYY-MM-DD to MM/DD/YYYY
Simpler approach
Another option is to construct a Date object (this can be achieved by appending a time at midnight to the date) and pass that to ...
10
votes
Accepted
If non-array property exists convert it to one and push new value
Basically after reading over the code, I interpret that the conditional (i.e. !obj[key].push) checks if the value at the given ...
10
votes
Accepted
Chart showing the Percentage of Answered CR questions
When I ran your script and started digging through the dom, I noticed that Apr 21 12:00 AM was missing -- I wonder why that was.
Anyhow, I wanted to encourage ...
10
votes
Accepted
Draw sine wave going around a circle
Overall you have a good D3 code here, congrats (I'm fairly impressed with the questions I've seen here at CR lately, from people claiming "This is the very first time I've used d3 or drawn a SVG&...
10
votes
Accepted
Restructuring JSON to create a new JSON where properties are grouped according to similar values
Scoping issues
You are using an "immediately invoked function expression" (IIFE) here to scope the unique_dates, but in the process you forgot to use the ...
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 ...
9
votes
Accepted
Vue.js search functionality
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 ...
9
votes
Counting words from stored .md files
How to modify this code, so it doesn't use forEach?
One way to achieve this is using Array.prototype.reduce():
...
9
votes
Accepted
Error solution: Uncaught TypeError
Does this open up the possibility for any buggy behavior that I don't know about?
It's not likely to. The if statement is fine, though it can be made cleaner:
...
8
votes
Accepted
Vue - It's the Royal Game of Ur
\$\color{red}{\textrm{warning: cheesy meme with bad pun below - if you don't like those, then please skip it...}}\ \$
Question responses
Do I have too many / too few components? I am aiming to make ...
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 ...
8
votes
Accepted
Reverse Integer
The question states that the input is a number 32 signed int so checking for undefined or null is a waste of time.
The solution ...
8
votes
Expanding powers of expressions of the form ax+b
You don't need the special case for k == 0. When k == 0, the result of the other expression will be 1 as well.
For this ...
8
votes
Accepted
Best way to preload images with callback on completion with pure JavaScript (ES6)
Firstly, kudo's to you for trying to use vanilla javascript. Great choice.
🤔 The Question
Let us start with your question:
[Is this code] an optimal way to preload images in pure JavaScript?
Sorry, ...
8
votes
Accepted
MMMRjs a product of BYTES Genesis
Comments
The comments such a This is Mean. are pointless.
And the comment
...
8
votes
Vue.js search functionality
Another way is to create an array from name and category and combine some method with ...
8
votes
Counting words from stored .md files
Another suggestion: with TypeScript, you only need to note the type of a parameter when TypeScript can't infer it itself. You might find it easier to read and write code when you avoid explicitly ...
8
votes
Restructuring JSON to create a new JSON where properties are grouped according to similar values
Names!
JavaScript convention is to use camelCase for names rather than snake_case.
Using a Hash Map
Using Array.indexOf to ...
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
Timezone-based VPN-detection
I'm not sure whether it is best to use .then(({browserTimezone, ipTimezone}) => ( ... or replace it with something like ...
8
votes
A Rubik's Cube game in Python
Documentation
The PEP 8 style guide recommends
adding docstrings for functions and the main code.
It would be helpful to add a docstring at the top of the code to summarize:
The purpose of the code: ...
8
votes
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ecmascript-6 × 664javascript × 629
algorithm × 73
programming-challenge × 65
functional-programming × 63
node.js × 61
object-oriented × 58
array × 41
html × 40
react.js × 38
performance × 37
beginner × 36
dom × 36
event-handling × 34
vue.js × 31
promise × 30
css × 28
jquery × 22
strings × 21
json × 17
game × 15
interview-questions × 15
iterator × 15
regex × 13
iteration × 13