Skip to main content
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
Results tagged with
Search options answers only not deleted user 23727

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

Verifying if a string can be created with the letters of another string

Your logic seems hard to follow. Why spread str2 to array, which you then read into a Set, only to turn around and make the Set into an array, which you then iterate, comparing each letter’s count in …
Mike Brant's user avatar
  • 9,638
0 votes

How to optimize two loop

const getStageByTask = (task) => { return stagesTasks.find( (stage) => stage.initialTasks.has(task) ) || null; } A few other thoughts: I am guessing that you are fairly new to development and/or javascript … In javascript, generally speaking, it is very forgiving about not using line terminators, but there are a few gotchas out there to be aware of in knowing how to write JS without ;. …
Mike Brant's user avatar
  • 9,638
3 votes
Accepted

When push data to array decide which key need to use

A few thoughts: First, you might consider whether the name/color property REALLY needs to change as output here. Why return { color: ... } in some cases and { name: ... } in others? This tends to i …
Mike Brant's user avatar
  • 9,638
4 votes

Knapsack algorithm in JavaScript - Integer weights and values

I don't think your algorithm actually works. First... while (totalWeight < capacity) { ...is not the proper criteria for determining when loading into the knapsack should be completed. What if th …
Cold_Class's user avatar
1 vote

Filtering JSON objects from array of values

new Set([ /* ids here */ ]); const isFilteredType = (element) => typeIds.has(element.type); // and later when filtering results .then( (out) => out.filter(isFilteredType) ); It is also customary in javascript … There is really not much of a reason to use var in modern JavaScript. You should primarily use const with let being used where the variable needs to be reassignable. …
Roman's user avatar
  • 2,843
5 votes

Array to key/value JSON conversion

Not sure that a class definition makes a lot of sense here since you don’t really have any real behavior being defined in this class. Destructuring can also help you populate variables from the inpu …
Mike Brant's user avatar
  • 9,638
0 votes
Accepted

Simple JS XMLHttp wrapper class

I am concerned that you have added a layer of false generalization around a very specific, usually one-time use, request object. I would think the class would be better named Request or similar to be …
Mike Brant's user avatar
  • 9,638
6 votes
Accepted

Codility binary gap solution using regex

The Regex is computationally heavy. I would consider simply iterating through the bits, keeping track of both the highest binary gap and the current binary gap. You could add optimizations such as th …
Ravi Chaudhary's user avatar
2 votes
Accepted

Transform an object into another object structure

So you have five data series here right (A through E)? What happens when you have 4 or 6 data series? Do you really want to rewrite your code? Also, unless you have some reason to do so, lodash see …
Mike Brant's user avatar
  • 9,638
1 vote
Accepted

Authentication using express-session

Thanks for your first submission for review. First and foremost, the thing that really jumps out at me is that this function is doing WAY too many different things. You likely should be considerin …
Mike Brant's user avatar
  • 9,638
1 vote

Minimizing duplicate routes index.js

This is where the Express Router class comes in. You could define a router for ‘api/v1/Project’, mount that router to you main app, and then add the individual routes to the router.
Mike Brant's user avatar
  • 9,638
2 votes

Convert a stream to Promise

I am not sure I understand why you are attempting to extend Writable here. At the end of the day, it seems as if your pipeline is what you are REALLY wanting to have a promise interface. Luckily thi …
Mike Brant's user avatar
  • 9,638
1 vote

JavaScript ES6 import / export

Your main.js does not have a direct dependency on Animal class, so much there is no reason to import it there. In fact, from standpoint of minimizing browser calls to include files, it might make bet …
Mike Brant's user avatar
  • 9,638
0 votes

Extension of JavaScript "typeof"

Outside of the other answers about the general utility of this function, I figured I would add some additional thoughts on the code itself. I do agree with those other opinions though that this functi …
Mike Brant's user avatar
  • 9,638
3 votes
Accepted

Custom function for serialization of form inputs (and selects)

You are not really implementing in plain JavaScript in that you are using jQuery inside the function. This seems to be an odd choice. Are you using jQuery or not? You should make a decision. …
Mike Brant's user avatar
  • 9,638

1
2 3 4 5
9
15 30 50 per page