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
10 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 ...
0
votes
0answers
12 views

The students reward list

The code needs to make the list of the students. Correct the names if it's needed and add a new students. And the teacher can give them the stars like the reward. I did it, but my code looks like a ...
-1
votes
0answers
8 views

how can i make the bot resend a message every time i restarting the project [closed]

when i do process.exit() and i start the discord bot project again will send a selected message in the selected channel and delete the old message witch created before i exit from the project with ...
3
votes
2answers
44 views

How to implement a 2D Cellular Automaton in JavaScript?

So far I have this: ...
-1
votes
1answer
33 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
15 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
147 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
89 views

Run-length coder

I have below code, which counts only adjacent letters in string and gives out count. ...
0
votes
1answer
39 views

React useState,useEffect - save variables to local storage

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
66 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
67 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 ...
0
votes
0answers
22 views

SPEED TYPING TEST [closed]

The question is that I have to create a speed typing test as shown in the link below goal I have to meet all these points: Add HTML container element with id speedTypingTest Add HTML paragraph ...
3
votes
2answers
47 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
23 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
56 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
59 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
47 views

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

I'm wanting to see if there's a better way to write this, 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
0answers
23 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
63 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/...
1
vote
0answers
22 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
15 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
30 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
65 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
50 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
40 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
35 views
2
votes
0answers
37 views

Custom HTML Element with scrolling text

A junior developer here. I wrote a simple javascript custom element code here: https://codepen.io/rndbox/pen/mdWxryw as clean as I could with some advice from Junior Vs Senior Code - How To Write ...
0
votes
2answers
62 views

How to refactor and reduce complexity of this code

code climate tells me this block of code has a Cognitive Complexity of 7 (exceeds 5 allowed). Any ideas how I would refactor this to reduce complexity? ...
0
votes
0answers
34 views

JavaScript optimize a function to check if a nested object is empty

My function needs to check if some nested object is empty. For flat objects, there is no need of recursion, and a very basic function could be the following (inspired to PHP empty): ...
0
votes
0answers
14 views

Pulling data from an API and working with it in Google Sheets

I'm trying to build out some DeFi position tracking pages in Google Sheets. I want to pull from the Zapper API (or other APIs) to track trades, positions, gains, losses, fees...etc. This is my first ...
2
votes
1answer
37 views

Client side Pagination implementation in vanilla js

I have made this Pagination Class in JS which takes the following configurations :- Total records Records per page Visible pages The idea is simple that any instance created using this Pagination ...
1
vote
0answers
70 views

Find the number of carry operations needed to add two numbers digit by digit

I don't know if my test cases at the bottom cover every case, or if my mathematical logic in the reducer function is exactly right (referring to the math that starts with ...
1
vote
1answer
31 views

Managing duplicate class instances in a javascript Set

I have a class called Thing. For simplicity, let's say it initializes with a unique id, and that's all that's unique about it: ...
1
vote
0answers
12 views

Fetch the nearest city, optimised with Redis on a Lambda

I have a lambda function which returns the nearest city from a latitude and longitude. My algorithm for this is resource heavy and time consuming. To optimise this, I hash the coordinates into a 6 ...
4
votes
2answers
314 views

Laravel 8 registration and login with user profiles

I am working on a Laravel application (Github repo) that requires user registration and login. Alter registration, the users can change their registration details (except password, for which there is ...
5
votes
1answer
169 views

JavaScript discrete slider web component

The standard HTML range input element suffers from a number of limitations that caused me to implement the web component presented here. First, it is unnecessarily complicated to style the standard ...
1
vote
2answers
53 views

Filter results by a search term

The below code filters my contacts according to a search term the user typed. Is there a way I can avoid explicitly writing all the object keys but keep the ...
2
votes
2answers
57 views

Find the 10001st prime number

Project Euler 7: What is the 10 001st prime number? I currently have this code: ...
2
votes
1answer
190 views

To-do app front-end in Vue 3

I have put together a To-do Application with the Slim framework on the back-end (API) and a Vue 3 front-end. I added a demo on my YouTube channel. In the main App.vue file I have: ...
0
votes
2answers
62 views

Reload control using loop

I created this working sample and the code is below. Any advice on how to make this code; cleaner, more effective, just overall better! The data is coming from an API and I need to parse, select the ...
2
votes
1answer
39 views

basic paging function, is there logical problems with the JavaScript part?

Basic paging function, is there logical problems with the JavaScript part? very basic paging function. I want to know if there are some problems in the logic of the code. I feel the JS code is a bit ...
4
votes
1answer
58 views

How to make my code shorter. This Code formats Credit card number. Vanilla JS

How to make my script shorter and better? This code allows only digits, auto-format card number like this XXXX XXXX XXXX XXXX. if user hits delete or backspace to delete space in between digits, ...
0
votes
0answers
17 views

Convert fs code to fs-extra using node js [duplicate]

i have code which used to read directory recursive and with given depth but i have wrote this code by using var fs= require("fs"); so my code look like ...
1
vote
1answer
41 views

simplifying regex expression for timestamp

I was wondering if it's possible to simplify this regex string (JS): ...
3
votes
2answers
56 views

concise way to build an object from an array of objects

The following code is working as expected but I'm wondering if there's a way to use Object.assign, or some other approach, to build the ...
0
votes
2answers
63 views

Simplifying the array of objects with comma separated values

Looking a way to reduce the below code to get comma separated values from the list of arrays By using ECMA or plain old vanilla JS. How should we achieve this? Actual Array Data: ...
0
votes
1answer
45 views

Fizz Buzz function that returns an array [closed]

I am a newbie to JS and I am working on a FizzBuzz challenge. Below is what I have tried. Essentially when the function takes a value then it would iterate from 1 up to the value and an array would ...
1
vote
1answer
29 views

Cleaning up and optimizing JavaScript code to check if an object contains a key that is present in a map

I have written the following code. It checks to see if the object contains the key where the key is present in the map. ...

1
2 3 4 5
185