Skip to main content
Share Your Experience: Take the 2024 Developer Survey
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 ...
Joseph's user avatar
  • 25.1k
33 votes

Using fetch() and a new Promise object to get API results

A few comments: 1) fetch already returns a promise, which means this: ...
elclanrs's user avatar
  • 2,535
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: <...
Sᴀᴍ Onᴇᴌᴀ's user avatar
25 votes
Accepted

Check if images are loaded (ES6 Promises)

Well, you normally don't want to use the Promise constructor in your higher level code, you want to Promisify as low as possible. So let's create a function that ...
Madara's Ghost's user avatar
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. ...
Nina Scholz's user avatar
15 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 ...
RoToRa's user avatar
  • 11k
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 ...
Gerrit0's user avatar
  • 3,456
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 ...
Taki's user avatar
  • 608
13 votes

Stack Exchange rev​iew queue notifications

I don't see much benefit to the enum. The Notification.permission string (or the return value of requestPermission()) is already ...
CertainPerformance's user avatar
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 ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
12 votes
Accepted

Selecting a prize category based on two parameters

To make @kfx's answer more readable: ...
kyrill's user avatar
  • 1,570
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 ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
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 ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
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&...
Gerardo Furtado's user avatar
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 ...
Vogel612's user avatar
  • 25.2k
9 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 ...
mickmackusa's user avatar
  • 8,674
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 ...
Blindman67's user avatar
  • 22.1k
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 ...
sɪʒɪhɪŋ βɪstɦa kxɐll's user avatar
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(): ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
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: ...
CertainPerformance's user avatar
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 ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
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 ...
Blindman67's user avatar
  • 22.1k
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 ...
Blindman67's user avatar
  • 22.1k
8 votes

Find all letter Combinations of a Phone Number

whenever you encounter a task where you have to combine or permute things, then backtracking is a possible approach. True. It is not necessarily the best though (in fact it is rarely the best). In ...
vnp's user avatar
  • 56.5k
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 ...
Roland Illig's user avatar
  • 21.3k
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,...
Maanlamp's user avatar
  • 506
8 votes
Accepted

MMMRjs a product of BYTES Genesis

Comments The comments such a This is Mean. are pointless. And the comment ...
RoToRa's user avatar
  • 11k
8 votes

Vue.js search functionality

Another way is to create an array from name and category and combine some method with ...
StepUp's user avatar
  • 553
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 ...
CertainPerformance's user avatar
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 ...
Blindman67's user avatar
  • 22.1k

Only top scored, non community-wiki answers of a minimum length are eligible