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.
8,875
questions
1
vote
1answer
19 views
Filter an array of objects, checking only specified properties and child objects
The function filterList recieves an array of objects and filters the list, checking only the properties of the object specified in a 'filterFields' array.
It compares the values of those specified ...
0
votes
1answer
22 views
Loading sound effects into an array
I'm loading my game's sound effects into an array to easily pick a random one and play it. Previously, I used a switch statement to select a random sound but it looks less verbose to just pick an ...
-1
votes
0answers
31 views
2
votes
1answer
12 views
Type definitions for simple NPM package that generates OAuth 1.0a authorization header for Twitter API using native https nodejs module
I added type definitions to a simple npm package. I would love to get some feedback on ways to do better for the type definitions.
The package exports a single function which returns a function that ...
2
votes
0answers
21 views
HTML5 Tile Cycle Puzzle
It's been a while since I did anything with JavaScript. I made a tile puzzle game to help me brush up. You can find it here: https://compucademy.net/tile-puzzle/
I would like some feedback on my use ...
2
votes
0answers
13 views
Pre setup script to get user metadata and check supported api's within the browser/device
Can this code be shortened or optimized,
Written out this script to be used before node.js
starts a few canvas elements and some vide streams.
wondering if the initial checks can be shortend or ...
2
votes
1answer
26 views
Infinite Slider Conversion to Prototype
I've found the following example of an infinite slider to use on a project but as I will have multiple instances I have converted it to a prototype.
The original example
https://medium.com/@...
3
votes
0answers
45 views
Image Generator with HTML and JavaScript
This is a working media generator using HTML and JavaScript. It's mostly meant to display one image at a time at the click of a button, but any type of media can be placed in the array (video, audio, ...
6
votes
0answers
51 views
JavaScript Tic Tac Toe implementation
I've been trying to get into web development, so I made a quick Tic Tac Toe implementation. It feels messy to me, but I'm not sure what is really considered to be good practice and what not. Any poor ...
4
votes
0answers
30 views
Very basic Vue todo list viewer
Problem
I keep trying to use various todo lists. But I keep coming back to the same situation; not having an active todo list. This can come in two forms:
I don't have a habit to open bespoke ...
-2
votes
1answer
45 views
Modify an array of object using ES6 Pure function [closed]
I am modifying an array of object using pure function but facing some challenge to modify userDetails object.
My requirement is instead 1, I need to show true inside permissions object. Please check ...
1
vote
0answers
39 views
Javascript to show folder and files by calling Web Api
I have this Javascript which call the web api to see the available folder and then the available files. Any comment or code review on my code?
...
4
votes
1answer
28 views
Class to automatically create Valve VDM files by timestamps
I'm currently working on a project which should create VDM files. Here's a basic example:
...
2
votes
1answer
68 views
To Do List Project - app lets you make projects and inside of this projects you can save to-dos
I have built a To Do App in Javascript, using Webpack and some modules. The app lets you store projects (School, Sport, Grocery, etc.)... And inside these projects, you can store todo items... You can ...
4
votes
2answers
528 views
Passing data from one promise to another using then
I'm trying to get an object with ratings and titles properties:
...
2
votes
0answers
41 views
The best way to handle many, different requests with custom query params
I have a list of products, I would like to filter that products e.g. by number, price, type etc. using checkboxes, selects and inputs. I get my data from REST API - using query params in GET method. ...
3
votes
1answer
36 views
Multiple anonymous IIFEs inside outer function
I have a scrollHandler function which contains all of my scroll event-listener logic.
I've used multiple IIFE's inside to ...
1
vote
1answer
26 views
Simple React component to show sorted articles
I have a basic articles sorting application, the App component gets some articles and pass them to the Articles component which ...
3
votes
1answer
67 views
Javascript / React data mapper
My solution to implement a status (string) from combining two other ones.
I need to declare a function which takes two params (two strings) and needs to return another one based on the combination of ...
9
votes
6answers
1k views
Method to delegate command to other methods
Since I am working alone on this, I would like someone who would take a look and point out any mistakes or things I could have done better.
My questions:
How could I improve this big switch statement?...
3
votes
2answers
85 views
0
votes
0answers
43 views
How to simplify and optimize bitwise get/set operations on a large bit buffer in JavaScript?
tl;dr: How could you rewrite the buf_get and buf_set functions below to be most optimal?
It took me a long time and a lot of ...
5
votes
3answers
92 views
Removing unneeded objects from an array before rendering
I'm making a function that adds a new object to an array and removes the oldest if it has reached a specific length. Click the button in the example below. All objects are drawn until its array ...
1
vote
1answer
46 views
Sending HTML reports to a database project
So, I have been recently heavily focusing on Front-End, for data validation, showing errors etc. And a big thank you to CertainPerformance for many reviews hes done for me :)
I have created a Report ...
-6
votes
0answers
21 views
redirect user after facebook share and publish [closed]
How can I redirect a user to a specific URL after clicking the share button?
...
4
votes
2answers
134 views
JavaScript implementation of Symbol Table (Dictionary)
I'm currently going over Robert Sedgewick Algorithms book. Here I'm implementing a Symbol Table using a Linked List. The Sequential Search Symbol table is implemented in JavaScript. The book mentiones ...
5
votes
1answer
38 views
Hide link formatting Firefox extension
I'm building a Mozilla Firefox extension to hide link's formatting and show them as regular text. It consists of a script that runs on web-pages (content.js) that's ...
2
votes
1answer
53 views
Double validation - but only show second validation after 1st one is complete in Javascript
Currently trying to learn to add in some validations, but only run 2nd validation after the 1st one is fully done and has no errors.
Just want to hear reviews regarding my current logic in my data ...
2
votes
1answer
25 views
Multiple audio player - arrow keys & space
I am creating a VueJS component of an audio player.
I am having some difficulties in finding the ideal way to get the arrow keys and space to work.
I have found a solution, however I think it is not ...
3
votes
1answer
58 views
I need some suggestions to speed up my array manipulation code
I have a function which from an array of days return the array of days with it's date like from array of
['Sun', 'Mon', 'Tue', 'Wed' ] my function returns the days ...
2
votes
1answer
45 views
Interview Coding Test: Transaction Processing: Find Duplicates
I had given a coding test for a job which failed. It had two problems and one of them is shared in this question along with my solution and other I already posted at this link.
Problem: Find duplicate ...
1
vote
0answers
38 views
Javascript Online Notebook
I use an online, simplified notebook. I'm able to add notes, delete notes, and edit existing notes. I find the code to be pretty unattractive and is heavily repeated.
When I built this, I borrowed ...
6
votes
3answers
453 views
Selecting elements from the DOM of a page
To get the book list from https://www.java67.com/2015/09/top-10-algorithm-books-every-programmer-read-learn.html , I am using the following code in the console of the firefox DevTools:
...
1
vote
1answer
78 views
Speed Efficiency of Decompression Algorithm
I've rewritten a piece of Javascript in Python 3.7 that decompresses a file compressed in a specific format. The project that I got this from is available here.
The code I've come up with is as close ...
1
vote
1answer
29 views
UI & Global Controller to hide `div` element based on `selected` option?
I have the following HTML + JavaScript code:
...
5
votes
1answer
88 views
Game of Life state calculation in javascript
I've created a Life implementation in javascript with the goal to be as fast as possible, with the rendering I'm satisfied (see picture bellow), hovever the next state calculation is really slow and I'...
1
vote
1answer
58 views
Rolling average over predictions
I am using a Deep Learning model I trained and want to improve its accuracy by implementing a rolling average prediction. I have already done it but want to improve it as I am making predictions on ...
2
votes
1answer
73 views
Algorithm to find bucket and item indices from power of two bins?
So this is building off of Algorithm for dividing a number into largest "power of two" buckets?. Here is a slight modification of the answer from there:
...
3
votes
1answer
60 views
Pure Javascript to create forms and validation check Project
Goal
I have developed a random check that I have thought of. I have used purely JavaScript to get used to the language and learn it. I have also used JavaScript to create elements, classes, id etc... ...
1
vote
0answers
50 views
calculator logic
How can I rewrite this if statement of which there are a lot. Or how, in principle, it can be rewritten to look good? This app is calculator. How it can be redone with a switch maybe. Or breaking it ...
6
votes
3answers
1k views
Counting words from stored .md files
The following searches recursively for all the .md files inside a folder. It then stores the text of the files in an array. Finally, it sums their word count using ...
4
votes
2answers
94 views
Regular expression to get a string between two strings where the last string can also be 'end of string'
I intend to extract a URL search parameter value using a regular expression in plain javascript. The parameter can be in any order in the search query.
So is there a better approach than 👇?
...
4
votes
1answer
72 views
React hooks update array of object
I have declared a react hook which will contain an array of object as follows:
const [rowDataTracker, setRowDataTracker] = useState([]);
Now I need to update the ...
6
votes
4answers
1k views
Convert minutes portion of time to decimal
I am making an hours calculator app. It takes a start time, end time and time taken for lunch.
For the start and end time it takes a four-digit hh:mm time. For example, 10:20.
I have made a function ...
3
votes
0answers
54 views
Looking for feedback on a simple finite state machine for logging in with xstate
I have a sample React app that loads a username and password, and then randomly provides a login result on submission for the sake of example.
CodeSandbox: https://codesandbox.io/s/stack-xstate-login-...
9
votes
4answers
2k views
Algorithm for dividing a number into largest “power of two” buckets?
For example, these are expected outputs:
3: 2, 1
4: 4
5: 4, 1
6: 4, 2
7: 4, 2, 1
8: 8
9: 8, 1
...
20: 16, 4
...
25: 16, 8, 1
...
36: 32, 4
...
50: 32, 16, 2
Up to ...
0
votes
2answers
138 views
Getting and checking value from a mixed object array HTTP endpoint
I try to get location data by a external HTTP call. For this API, any part in the data can be missing. Initially I wrote the following code to check whether ...
6
votes
1answer
102 views
Code to change the size of the fields based on that 2 fields are optional inside a contact form
In my React app using Material UI, I wrote a code to manage the size of the fields of a contact form. Those fields are elements that can be added or removed depending on a configuration.
The code I ...
0
votes
1answer
48 views
Refactor multiple if condition in JavaScript/TypeScript
I want to refactor this code but am wondering how I should start it. I'm not sure this code is totally against clean code or not. I'm thinking to use RxJS or a JavaScript builtin method. I'd like to ...
4
votes
3answers
107 views
Image toggle with checkbox and onclick
I have an image toggle triggered by button clicks and checkboxes. My code is currently working how I need it to, but I'm very new to JavaScript so I'm sure there is a cleaner way to do this.
The ...