Questions tagged [javascript]

JavaScript is primarily a language focused on web development. Being a monopoly on the front end and having Node on the back end. 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.

Filter by
Sorted by
Tagged with
0
votes
0answers
3 views

Stack Implementation in JavaScript

I am learning data structures and below is my implementation of a stack in JavaScript. I didn't want to use built in functions for an array because in JavaScript that would be too easy, so I made my ...
0
votes
0answers
7 views

How to make a NodeJS + ExpressJS API bulletproof?

I just started to code my first API, I'm very excited about it and looking for some advice & feedback to make my code better and secure. I thought my code is perfect as long as I called my API for ...
1
vote
1answer
33 views

Project Euler 1 using functional programming in JS

So I am once again beating a dead horse, by solving the first Project Euler problem: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these ...
2
votes
1answer
23 views

Generate Multiple Instances of Canvas-based UI Object

Background I'm interested in implementing a small script to display multiple independent instances of a Canvas-based control on one page. The ultimate intention is to add many similar controls to the ...
1
vote
1answer
30 views

Hidden html elements after search click

I want to: Hide areas of my template after search click. Return its original state with the cleaning of the input related to each button. I don't know if my code exploits all the resources of ...
-1
votes
1answer
32 views

JS - Same recurring statements in if-else

I have this watcher in my app.vue that makes sure the right theme attribute is set on the ...
0
votes
1answer
28 views

Opinion on mutating the accumulator in Javascript Array.reduce function? [closed]

I wrote this reduce function and got comments on my pull request saying that mutation is not good practice, however, I only mutated the accumulator and I didn't see any benefit of creating a new ...
0
votes
1answer
60 views

Simplifying and optimising function logic

I asked the same question on StackOverflow but was told to instead ask here since it was better suited. I have a function that I implemented. It is doing a lot of heavy lifting. I would like to ...
2
votes
2answers
47 views

First non-repeating character in string

I've been trying to learn a bit of JavaScript over the last few weeks, and inspired by this current hot network question, I tried creating a function for finding the first non-repeating character in a ...
0
votes
0answers
21 views
+50

Which of these two Vuetify Navigation Drawer prevent prop mutation workarounds seem better?

I am very new to Vue.js, I just stumbled on a very hard thing to do (at least for me) where Vue was complaining about mutating a prop (children shouldn't change parent props apparently), I was about ...
2
votes
2answers
41 views

JS script fetching GitHub API for personal website

I've built a very simple personal website, everything is in a single file because it is very straightforward, but I think the JS script could be better structured. All it does is fetch some repos from ...
0
votes
0answers
38 views
+100

list of games to open radar match in iframe on for drop-down controls

In general my page is slow and has several points in the code that I believe can be improved, even in relation to the structure used. Anyway, the biggest problem is: The page I'm creating is very ...
2
votes
1answer
49 views

Is this a reasonable way to test/compare javascript loop speeds?

I'm playing around with understanding array looping speed. I'm trying to make the contenders equivalent and close to realistic. Is this a good approach? Are there other iteration approaches to test? ...
1
vote
1answer
41 views

Maximum Profit in Job Scheduling - Performance Issue

I implemented the Maximum Profit in Job Scheduling algorithm in JavaScript, but I'm having performance issue. The problem: We have n jobs, where every job is scheduled to be done from startTime[i] to ...
0
votes
0answers
41 views

Shortest Path to Get All Keys - Algorithm in JavaScript [closed]

I implemented a JavaScript solution for the problem below: We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a&...
-1
votes
1answer
29 views

refactor multi if statements and checking for div existence in a better style

I want to refactor this code to a better version without all this repetition, this code is working 100% the way it is right now but every refactoring effort is making it useless, any idea or can this ...
3
votes
2answers
101 views

Single user Electron application allowing basic CRUD operation on a table (stored in JSON)

I am completely new to JavaScript and I will be grateful for your comments on my Electron app (electron is a JS framework allowing to create of desktop apps). I needed to create an application that ...
-1
votes
0answers
43 views

What would adding a state accumulator to my simple framework solve/add?

I've created a simple node modules that allows displaying a matrix of characters in the terminal, as well as capturing keypresses. The purpose of the tool is to make simple games like snake, space ...
1
vote
1answer
65 views

Square Spiral Matrix in Javascript

I've been grinding some Leetcode for an interview coming up and just completed Square Spiral in Javascript. Looking for feedback on performance. This ranked faster than 58% of submissions, would there ...
2
votes
1answer
93 views

In how many different ways can a group of 9 people be divided into 3 groups, with each group containing 3 people?

To divide 9 persons into 3 groups, when the ordering of groups is not important can be done in (9C3 * 6C3 * 3C3) / (3!) = 280 ways Here, we divide by (3!) because the ordering of 3 groups is not ...
3
votes
2answers
77 views

Javascript (ES11) Event System implementation

So I decided to implement a basic event system in JavaScript. My goal was to support the following functions: on - allows the user to register a handler on the ...
0
votes
1answer
24 views

Appending script from within function to header [closed]

I'm attempting to import an external script into an HTML file. The name of the js file that I want to import is hosted in a SQL database. Therefore, I am using a XMLHttpRequest to access the SQL ...
1
vote
0answers
42 views

Genetic Algorithm Typescript

I learnt a little about genetic algorithm. And I made a program from typescript that tries to evolve and match word/sentence using genetic algorithm. But if I give a little longer sentence it takes ...
1
vote
1answer
40 views

Recursively access deeply nested object

Problem Statement I need to access a deeply nested object. I could've used a 3rd party util such as Lodash but insisted myself on writing a Vanilla JS solution with a recursive strategy. Code Can this ...
1
vote
1answer
21 views

abstract navigationOptions react navigation

I have many stacks with the same navigation options, how do I abstract the navigationOptions part to have it repeat in all my stacks? ...
1
vote
0answers
19 views

Mix JavaScript debounce (not plugin) with jQuery event handler?

I asked this on StackOverflow and was directed here... Instead of including a debounce plugin library for a very small form section of my site, I've implemented some of David Walsh's JavaScript ...
0
votes
1answer
41 views

Refractor a function call [closed]

I am working on an API call in pure Javascript and I hit a section of code that i want to refractor The code is something like this ...
1
vote
1answer
100 views

Is My Controller too Coupling?

To put it in context, I had the assignment to do for a job interview in Node.JS, which basically making CRUD with products (and it have certain conditions). The assignment was well-understandable, and ...
0
votes
3answers
64 views

Get the Most frequent element in an array

I have been trying to optimize this: ...
2
votes
1answer
60 views

React-based resizable sidebar

I am an experienced developer, but new to the react and the javascript world. I am trying to create a resizeable sidebar in react(Please see the full code and demo here) for a personal project. ...
2
votes
1answer
52 views

Turn an array of pairs of start and end points into an ordered series

Given an array of pairs, for example: [["Denver", "Miami"], ["Miami", "Tulsa"], ["LA", "Okmulgee"], ["Mobile", "Portland"...
1
vote
0answers
29 views

Synchronizing clients in javascript without my own backend

Warning: sound (not loud, and volume is set to 0.5 in the code) My goal here is to get anyone who enters the webpage synchronized as well as possible. Say there's some global clock. Since Javascript's ...
0
votes
1answer
28 views

Typescript angular queryparams

I have some code like this ...
2
votes
1answer
53 views

Web-browser Tic-Tac-Toe game

I have made the tic-tac-toe game as part of The Odin Project course. I think the code I have written just works but is not properly optimized for performance and it could be made simpler. This is ...
0
votes
1answer
40 views

Function that decodes all values of a given object from Base64

I have function decodeVals in NodeJS that decodes all of the values of the given object from Base64 to ASCII. This is achieved by traversing the values of said ...
0
votes
0answers
43 views

Sliding Puzzle Problem in JavaScript

I'm trying to solve the Sliding Puzzle problem in JavaScript. The problem: ...
2
votes
0answers
68 views

Fetch in JavaScript, but less messy?

I'm trying to separate the fetch logic from the component, but, due to the nature of async/await functions I have to write an async function to call other async function and I wanted to know if that's ...
0
votes
1answer
61 views

Cheapest flights within k stops algorithm in JavaScript

The problem: There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is ...
4
votes
1answer
63 views

Convert ASCII representations of phonetics to Unicode characters

Here is some working code for converting an input string to an output string: ...
5
votes
3answers
717 views

Employee Model definition without an ORM

I am the author of this code. It's from an actual project, and it returns the desired result. However, I am very concerned that I'm not defining my Model correctly. The Model is instantiated in the ...
0
votes
1answer
47 views

Unit tests for individual methods of a calculator

Recently I needed to expand the exports in a file to all methods in order to allow for Jest tests to cover more of the code (without using Rewire). Beforehand, only the functions used by other ...
1
vote
1answer
62 views

Making my login function more readable and maintainable

I recently wrote a login function in my express application that does the following: Verifies the user's email and password are correct Generates a JWT Access Token with a short expiry date, and then ...
1
vote
0answers
24 views

Splash Screen Library in jQuery

I have created Splash Screen Library in jQuery, The Splash Screen will display until the website completed loading all the images. I just wanted to review if there is any improvements for the code. ...
3
votes
2answers
60 views

Javascript best way to filter out empty values and simplify reusable function

Hello I have this function that takes array of objects and takes a specific value from the object and creates array of strings that can make mapped to dropdown selector. ...
2
votes
0answers
43 views

Resilient JSON.stringify that never throws

I'm trying to write a JSON.stringify wrapper that never throws exceptions, and also includes properties like those on Error. I think this means it has to: handle ...
1
vote
0answers
39 views

Flask Session + Jinja OR Javascript + Flask

I'm a beginner in programming and I'm figuring out what is the best approach for my mini e commerce site project. My current approach is ...
1
vote
1answer
50 views

Checking if two shapes collide in TypeScript (double dispatch)

Basically, I'm trying to create a generic way to check if two shapes are colliding. I think this is kind of a "double-dispatch" problem, but I'm unsure if there is a better way to solve it ...
4
votes
1answer
46 views

Deal and evaluate a Bridge hand

I am building a little helper for the card game Bridge. The aim is to generate a "hand" of 13 randomly-dealt cards, and then to run various calculations on the hand to help a player with the ...
0
votes
0answers
35 views

Optimize Javascript User Mentioning

I want to replace every div with the class mention. The text should then be parsed and all the parts with ...

1
2 3 4 5
186