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
22 views

How to remove duplicates of code and apply pattern?

I have the following class: ...
1
vote
0answers
29 views

Cron expression parser

Problem Write a command line application or script which parses a cron string and expands each field to show the times at which it will run. ~$ your-program "*/15 0 1,15 * 1-5 /usr/bin/find"...
-1
votes
0answers
26 views

Code refactoring for services and controller based architecture node.js

I have my app structured as below, Routes -> Controllers -> Services So, for /bookings there is ...
0
votes
0answers
17 views

Optimized method of transfering numpy image arrays over localhost to web-tech UI for desktop UI

I have been doing testing to find the most efficient way to display numpy array images to a HTML, CSS, JS UI (specifically, with CEF Python). I mainly used the method explained here to do the numpy ...
2
votes
3answers
69 views

Sort an array of integers with a hashset

I was trying to make a sorting algorithm for an array of integers. Here's are the steps/theory: It turns an array into a HashSet, iterates over every integer value ...
0
votes
1answer
63 views

loop inside loop over one array

I have the following code: ...
0
votes
0answers
18 views

Three.js with lottie on canvas implemented in A-frame [closed]

I'm actually trying to use AR.js to display a lottie.json animation, so far i've found some help in bringing lottie.json to display on a canvas in three.js, now its to bring it to a-frame, but i can't ...
-1
votes
0answers
14 views

Generic CRUDL service [closed]

I'm writing a generic CRUDL service as a base for a lot of simple objects that operate similarly on the database. My first though would be to write something like this: ...
0
votes
1answer
30 views

How to make DRY logger class with debug, info, warn and error methods that extends private method

I am trying to make logger class with debug, info, warn and error methods that "extends" basic log method. However it is not written using DRY principle, how can I make it DRY, not WET? Code ...
0
votes
0answers
28 views

Find number of times a property has a truthy value in a nested object

I have a nested object and I would like to calculate the number of times the property 'error'. I am able to go n levels deep and find the count. Is there a better solution than mine? ...
1
vote
0answers
18 views

Testing a javascript function that performs side effects

Application context I am working on a game I call "Apes and Snakes". So far the code only allows players to connect to a host using a room code and WebRTC. Players and the host send messages ...
-2
votes
0answers
18 views

How do I make the modal popup stay still on top of another modal? [closed]

I am creating a company Directory and I've got the main page, with all the contacts, and two modals, so basically when I want to delete a contact from the directory I press on the delete button inside ...
0
votes
0answers
25 views

How to optimize loops and apply reducer for array? [closed]

I have the follwing code: ...
12
votes
3answers
3k views

Discord bot for ordering food

I'm new to JavaScript, and I made a Discord bot using discord.js that serves food and drinks and replies without the need of a prefix. My issue is that I want to try cleaning up the code and get rid ...
0
votes
2answers
70 views

Reduce cyclomatic complexity for a pipe filtering over 4000 objects in ngFor in Angular 11 [closed]

The pipe shown below has to filter over 4000 objects and into two properties values of the object every time the user type something on an input field which is really bad I'd say How could I improve ...
1
vote
1answer
41 views

Lookup an array against another with performance

I got an initial array, I am checking against another array to find how many objects have at least one instance of the Domain in data. I wonder if there is a more ...
3
votes
2answers
45 views

implement the merge functionality for 2048 with JavaScript

I am trying to implement the game 2048 using JavaScript. I am using a two-dimensional array to represent the board. For each row, it is represented using an array of integers. Here I am focused on ...
0
votes
2answers
42 views

Script for showing/hiding on click - how can I write this code cleaner?

I have this simple code, but it's messy - how do I do it cleaner? It works like this: If you click on the menu-btn1 the div ...
0
votes
1answer
26 views

Optimize “nearest” Element query prototype

I have devised a recursive function to grab the "nearest" element. This is a bit different than Element.closest, because instead of traversing just the ...
4
votes
1answer
26 views

Put every object in a specified bucket

I have this array of objects: ...
0
votes
0answers
11 views

Facebook Login with JS and validate with PHP - Secure?

I am using Facebook's Javascript SDK for the login, and I am validating it with PHP Graph SDK v5.x Here is the JS: ...
0
votes
1answer
24 views

Calculating ordered differences between elements in vector

Input I start with a vector of integers or floats, e.g.: [10, 100, 20, 5, 50] Output I want to return a list of differences or "deltas" between elements ...
2
votes
2answers
44 views

Numeronym generation

Problem statement I need to generate numeronyms from a string, let's say qwerty as follows: qwerty q1erty q2rty q3ty q4y Code ...
3
votes
1answer
43 views

Carousel Using Vanilla Javascript

As a beginner project, I've start working on this carousel slider that would slide through an image and a testimonial on click. The number of images and content slides would always be the same number. ...
2
votes
1answer
44 views

Javascript. Reverse order of words in string, but not special characters

Hello I am hoping someone can provide me feedback on my solution to this prob. If there are additional edge cases I should consider etc. Thank you! The question: "Given a sentence with a set of ...
4
votes
1answer
59 views

Generate all partitions of a set of items

Here are the items: var item = ['a', 'b', 'c', 'd']; Desired output: ...
0
votes
0answers
17 views

Custom hook to have a featureList OBJ inside a useMemo()

In my React app, I had to build a system to check access based on roles and features. To make code more efficient I should move the function which makes a list of an featureList OBJ of features inside ...
3
votes
1answer
126 views

Submitting form jQuery checkboxlist

In my requestForm submit function I have this logic that checks three checkboxes and then displays the label with an error message. Is there better logic? I would be happy for any kind of feedback ...
0
votes
0answers
32 views

Taxi fare calculator based on distance and time in a threshold

I would like to create a taxi fare calculator which will take as params in a threshold the following: ...
2
votes
1answer
115 views

Strip all comments and create a new file with only (JS) code

This code hasn't been tested exhaustively - I would love suggestions about a testing library. Critical, Optional and Positive feedback are more then welcome. ...
0
votes
0answers
15 views

Advice converting an onCreate firebase cloud function trigger with FCM Messaging to support async/await and database reads

I initially had a simple firebase cloud function that sent out a push notification to a topic when a new message child was created in my real-time database. But I wanted to add message filtering where ...
0
votes
1answer
42 views
2
votes
2answers
144 views

Queue with O(1) enqueue and dequeue with JS arrays

If you simply implement it with .push() to .enqueue() and .shift() to ...
0
votes
1answer
45 views

BMR calculator web app written in HTML/CSS/Vanilla JS

I'm learning JavaScript at the moment (still very much a beginner) and this is the first app I've designed on my own, without using any tutorials. It's an app which takes the user's gender, age, ...
1
vote
0answers
26 views

HTML 5 Canvas Drawing app

I made a small simple drawing app using HTML5 Canvas, learning how to use canvas. You can right click to change color, scroll to change brush size, and click + drag to draw on the screen. Any feedback ...
3
votes
1answer
52 views

Collect distances from 1 point to all others in a graph

Problem: I have a weighted graph. I want to get distance from definite point to all other points in the graph.(and then get path to them) I used modified dijkstra algorithm So, here is code: ...
2
votes
0answers
61 views
-5
votes
0answers
24 views

Rxjs - How to rewrite nested subscriptions [duplicate]

I need an help to rewriting this subscription, it works but I don't like how it looks like. I'm working in Angular and in Ngonit of my dashboard component I need to call two services. For doing it I ...
1
vote
1answer
64 views

Check for empty object

I have a modal for adding new contacts, in order to disable the save button if no data has entered I check if the contact object is empty, is there a shorter way to check for an empty complex object? <...
2
votes
1answer
49 views

React material UI tabs in a different way

In my react application I have Tabs done with Material UI. Some of those tabs are shown or hide depending on an option is true or false. The code is not a clean solution but I have no experience ...
0
votes
0answers
14 views

Creating a reusable multistep wizard with react, redux, and formik

I am developing a multistep wizard for complicated forms in our app, in a react-redux context, with formik. There is one such wizard already in the app, but it is not reusable. I am in the process ...
0
votes
1answer
51 views

Import XML files to MongoDb with Nodejs

Here is my code which will read XML files and import the data to MongoDb. Do you have any comments on my code? ...
1
vote
1answer
59 views

How can I upgrade my validation in JavaScript?

How to improve my validation in JavaScript? Namely I am wondering whether some parts of code can be shortened, improved, or removed althogether. I don't want to change the ES5 syntax because so far I ...
0
votes
2answers
66 views

Solve binomial coefficient without lookup

I want to solve for n in the expression (binomial coefficient): \$y=\frac{n^2+n}2\$ let y = (Math.pow(n, 2) + n) / 2; I know ...
0
votes
1answer
40 views

Refactor dynamic filter functions

I create this menu filter component: with this menu, in practice, you can filter on a cards list feeling free to choose different filters at the same time; the cards list returned will be the results ...
0
votes
1answer
80 views

Find the odd int challange

this is a function given an array of numbers to find the one that appears an odd number of times. what I did is: Sort the array Check if the array is odd. If the array length is 1 then return this ...
1
vote
1answer
28 views

Best way to optimize similar payload (React)

I have to do some optimization on the function presented below. It makes some data like a payload based on the arguments passed into it. I am not much sure how to improve the code to look better & ...
2
votes
1answer
82 views

JavaScript: proper user of SJCL encryption in Google Apps Script

I'm using the minified version of SJCL to encrypt the backup files requested by the users. It is in a Google Apps Script add-on for Google Sheets. I'm mostly concerned with correct use, exception ...
1
vote
0answers
45 views

Does my first npm package follow best practices?

I have created my first npm package: https://github.com/sunnysideup/stretched-bg-image. The purpose of the package is to add a class to a div (or any other block element in the HTML) depending on the ...

1
2 3 4 5
183