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
1
vote
1answer
108 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
77 views

Get the Most frequent element in an array

I have been trying to optimize this: ...
2
votes
1answer
180 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
58 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
30 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
37 views

Typescript angular queryparams

I have some code like this ...
2
votes
1answer
67 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 ...
1
vote
1answer
52 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
53 views

Sliding Puzzle Problem in JavaScript

I'm trying to solve the Sliding Puzzle problem in JavaScript. The problem: ...
2
votes
0answers
74 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 ...
1
vote
1answer
129 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
68 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
735 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
56 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
64 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 ...
2
votes
0answers
28 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
65 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
44 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
46 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
61 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
52 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
36 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 ...
3
votes
0answers
58 views

Language switcher for a multilingual site

I have written some javascript code for a multilanguage site. The code works great but I feel like I have a lot of duplicate code. I was wondering if someone can explain how I can make this simpler or ...
2
votes
3answers
103 views

Check if array of strings have the same substring

I have a list of files that conform to a template like this: XXX_{project}_{variation}---XXX.html and ...
0
votes
0answers
18 views

Mutating the shopping cart using redux-saga

I am trying to implement a shopping cart using redux-saga. The following code is working fine. But it does not look right to me. I am mutating the cart whenever I am adding the product. Let me know if ...
0
votes
0answers
27 views

Calculate minimum buy/sell amount that exchange will allow the order to be placed based on current price

I have created calculateMinimumAmount to calculate the minimum buy/sell amount that exchange will allow the spot order to be placed based on the current price. The ...
3
votes
2answers
151 views

How to implement a 2D Cellular Automaton in JavaScript?

So far I have this: ...
-1
votes
2answers
57 views

concise alternative to a while loop

The following code works fine to generate an array of 6 random values (or however many are specified by iterations). I'm wondering if there's a more concise way ...
-1
votes
1answer
18 views

How do I distinguish the difference in naming and file structure between components and mobile components in React? [closed]

Here is my example structure: . ├── App.jsx ├── index.js └── src └── components ├── Button.jsx └── Header └── Header.jsx Question: ...
3
votes
1answer
175 views

Sanitation and validation of a user input 10 digits phone number

phoneNumberCheck() is using 2 helper function to check if a users input of a phone number is valid. this is a client side check, if this code is ok should I check the same at the nodeJS back end? is ...
1
vote
3answers
117 views

Run-length coder

I have this code, which counts only adjacent letters in a string and returns the count of each letter. ...
0
votes
1answer
72 views

React useState,useEffect - save variables to local storage [closed]

I'm new in React and state hooks.I'm trying to make a website about creating booklist and save it to local storage. Also uploading image to cloudinary. My problem is ; when i trying to save cloudinary ...
2
votes
2answers
190 views

Keeping only every nth element in an array in JavaScript

I have two arrays, arr_of_frequencies and float_array, of the same length — around 500-800k values each. I have to get that down ...
4
votes
2answers
140 views

File naming (two files cannot have equal names)

This is a challenge I completed at CodeSignal. You are given an array of desired filenames in the order of their creation. Since two files cannot have equal names, the one which comes later will have ...
3
votes
2answers
78 views

Show/hide for multiple IDs

I'm don't know much about javascript, but and slowly learning through using other people's code. The below code I'm using is quite repetitive, with the only variance being the ID names. I feel like ...
1
vote
0answers
58 views

More Efficent Code for Announcment Command in Discord.js

I am creating a command in my discord bot to send an announcement to every server it is in, and this is the only way i could think of doing it, but i know there is a more efficient way of doing it. ...
1
vote
1answer
46 views

Can this code be improved regarding map with in a For loop

I am looking for best performance regarding this code point is I don't have a clear idea weather a map integrated in a for loop is a good idea, the problem is the array is a nested object coming from ...
4
votes
1answer
60 views

Add result-logging to any function

I'm writing a simple function to transform functions by logging the result before returning it. The function as written by me: ...
6
votes
1answer
80 views

Improving product configurator "algoritm"

I have created a product configurator in VueJS and the whole functionality of it runs on one single function. I've put the word algoritm in the title in quotes because I don't really know if it is ...
3
votes
2answers
61 views

Limit second <select> options based on the first <select>

I want to see if there's a better way to write this code, solely in Javascript. There are two kinds of sets, the first set (C7, T7, C11, T11) have four options in the first select, and then up to two ...
0
votes
1answer
32 views

Draw shapes using the Html5 Canvas api

A while ago I decided to start working on a project that will keep me busy for a while and will help me sharpen my programming skills. I do not underestimate the work behind apps like adobe xd, sketch....
1
vote
2answers
65 views

Each item of the array must loop and show message for some time (duration) and repeat msg each value of delay

Is there a better way to loop item of an array using forEach and make repeat it using setTimout/...
2
votes
1answer
64 views

Typescript type checking of hierarchical types

I want to create a hierarchy of Typescript interfaces because I think classes would be an overkill in my case. The main obstacle is checking if an object has a specific type. I solved it this way: <...
0
votes
0answers
26 views

Is there a better way to copy dynamic data from one sheet to another in google sheets script?

I'm pulling data in from an API and putting it in the top two rows of a sheet. This script is to copy the data from the "pull" sheet into a daily sheet. The rub is that the data may change ...
10
votes
4answers
1k views
2
votes
0answers
31 views

Javascript client storage with the same persistence as a session cookie

I want to implement a client storage mechanism that is as persistent as a session cookie but with more storage capacity. I am doing this by encrypting the data before storing it and saving the keys in ...
4
votes
1answer
69 views

JavaScript Binary Search -- first try

EDIT: code snippet added, check the output in JS console I wrote the following binary search algorithm in JS, for the first time in my experience. The variable ...
2
votes
0answers
55 views

What to add to a Flappy Bird JavaScript code

I have a 200 line fully functional flappy bird code but I was told it's suppose to be 250 lines. I don't know what more I can add to the js of the game to improve it and make it longer. I was told I ...
2
votes
1answer
45 views

Is there a better approach to group the props and get the count of an object of arrays in javascript, less code but native approach

Could anyone help me with below logic implementation. I am new to Javascript and have been practicing advanced functions. The below code does the job but is there a better way to achieve the same? I ...
0
votes
1answer
43 views

1
3 4
5
6 7
190