All Questions
9,398 questions
7
votes
4
answers
5k
views
Verifying a South African ID
I'm verifying South African IDs with jQuery, the code below works but Id like to know if it could be simplified in anyway or if there is a better way of doing things here?
South African IDs are ...
6
votes
1
answer
439
views
Minesweeper game implementation in (vanilla) JS
I decided to write my own version of a Mine Sweeper game as an excuse for a Javascript/HTML/CSS project. Just to make the question self-contained: Mine Sweeper is a game with a rectangular board ...
0
votes
3
answers
63
views
function to get title from result object depending on if title is empty [closed]
I want to rewrite if else statements with something nicer or refactor the code i have to something neat using javascript.
below is the code,
...
5
votes
2
answers
642
views
Display properties of a country, from online service
I'm currently learning Vue JS and I made a simple app that pulls information from API and displays facts about a country given a 2-letter country code. I'm looking for feedback on how to improve the ...
0
votes
0
answers
48
views
Enable a textbox when the previous one is no longer empty
I've written this JavaScript code, which disables textboxes if the previous textbox is empty. This is so people enter the text in order — write first in the first textbox, only then the second textbox ...
2
votes
2
answers
327
views
Node.js configuration object based on environment variables
In the code below, I am building a NODE_ENV-sensitive config object from environment variables.
...
1
vote
1
answer
79
views
Improving player button control code
Would somebody be kind enough to show me the best way to loop through this so it much more efficient that just repeating everything?
...
4
votes
1
answer
97
views
Refactoring duplicate validation by array column wise
I am creating a functions to validate the array's duplicate by column wise from the given array. it works. Any one help me to minimize my code:
...
1
vote
1
answer
160
views
Simple calculator project
This code displays a simple decimal calculator with operations like add, subtract, multiply and divide. It also has a function to clear the result.
I try to reduce code repetition. I still think I ...
0
votes
1
answer
141
views
Separate a list in two lists using JavaScript
I have a list of events. They are html elements.
The premium events have a data attribute in their parent element: data-premium-event.
I need to separate the events in two lists:
a list of premium ...
0
votes
2
answers
124
views
Create an array which contains one object per objectid
Is there a better or simplified approach to create an array which contains one object per objectid with an array of contacts that matches globalLkupRemoveContactReviewer by userid and then send each ...
3
votes
1
answer
157
views
API calls organization in Ionic (Angular) application
I'm doing a prototype of server API calls in my Ionic (Angular) application. I'm considering this use case:
...
3
votes
4
answers
120
views
Javascript date / time display
I'm writing a simple start page and it's my first time with JavaScript, my previous background is Python/VBScript. Is it good enough? What best practices should I apply? Should I compress and nest the ...
9
votes
2
answers
1k
views
JavaScript Tic-Tac-Toe web app
I am teaching myself JavaScript and made a little Tic-Tac-Toe web app. I'm not asking anyone to read through it all, but to just tell me what I need or should not do in the future.
...
1
vote
1
answer
130
views
Sign Up Page - A mini Frontend Project
I have designed a a small frontend project, a sign-up page. It uses HTML, CSS, JavaScript and jQuery. Being a beginner to frontend development, I want to adapt to all the best practices. I am looking ...
1
vote
2
answers
414
views
group countries by language in JavaScript
I need a better implementation than the below code (O(N) Solution), I am grouping countries by language ( data ) is the countries JSON, each country could have 0, 1 .. or more language as the object ...
0
votes
1
answer
258
views
code to format text input to 2 decimal places before computation
I have this piece of code that checks the input of a text box before I compute for my main logic. This looks like it should be refactored but I'm currently stumped how to do so. The only thing that ...
1
vote
1
answer
69
views
Multiple grouped value select component
I've been designing a React component to select countries that a user has visited, grouped by continent. This component is a part of larger project but is relatively self contained. This is my first ...
3
votes
0
answers
92
views
Speed up a JavaScript function for inverting matrices using Gauss elimination
I wrote this function and I'm interested if it can be sped up by improving the code.
The function accepts either column major 1D array or 2D row major array.
Maybe there are some obvious JS tricks ...
1
vote
1
answer
135
views
Rock, paper, scissors game in expressjs typescript
This is a simple 2 player game made in NodeJS and the ExpressJS framework with typescript. I've built using OOP approach to as far of an extent as I know of it. I'm really curious as to how further ...
6
votes
2
answers
444
views
Sending Email Through App Script
Background
This is a function that is part of a library written in GAS. A function inside a library I've written is supposed to send out an email to another user or users with accompanying details (...
1
vote
1
answer
60
views
Match an array of date strings to the current calendar selection
I have an input array of month-year strings of disabled months selected by the user:
...
3
votes
1
answer
593
views
Movie app using fetch API
The code will create a new Movie class and then with the response of the API call, will render html using the data.
Although the code works, I imagine it will get quite convoluted, now that everything ...
2
votes
1
answer
212
views
All-JavaScript WhatsApp button
The following code creates a WhatsApp button.
How would you improve this code?
...
2
votes
1
answer
56
views
Multiplayer javscript game client side
Any improvement suggestions are welcome, as I'm not the best at making games lol. I have it structured like how Java would be because in the future I want to make it run on java and in the browser.
...
2
votes
0
answers
26
views
Calculating the worst outcome from a list of values
Given an array of severity from an external risk management system
...
1
vote
1
answer
111
views
One-time password verification
I've built a small OTP code verification component and I need reviews and suggestion to improve its performance and maybe the logic behind it. The purpose is to publish my first 'react component' to ...
1
vote
1
answer
154
views
Copy and Pasting Values from Spreadsheets
Background
This code is apart of a library I'm developing for my company. It takes in anywhere from 3 to 5 arguments. All of the code functions properly. To be more specific, a user has data on a ...
3
votes
2
answers
119
views
Idempotent JavaScript script loader
I wrote an idempotent script loader (for the browser), where the same script won't be loaded more than once.
scriptLoader.js:
...
4
votes
2
answers
94
views
Vue.js - Sierpinski Triangle
Below is a Vue app I wrote to draw a Sierpinski Triangle given n iterations, which can be incremented/decremented via a HTML ...
0
votes
1
answer
71
views
JS "Tabs" element
How can this be improved?
I'm looking particularly at the twice repeated tabButtons.forEach(button => {
...
1
vote
1
answer
72
views
PaginationBar component that renders links or buttons depending on optional callback prop
I have several components/pages in my personal project that contain complex logic and even nested ternary operators. Since I'm the only person working on this project, I don't have a hard time ...
2
votes
1
answer
143
views
sanitize untrusted input for templates
Attempting to populate HTML string-templates from untrusted input.
...
1
vote
1
answer
84
views
Pulling Data from an Email and Pasting it into a Google Spreadsheet
Background
The reason why I'm doing this is because at my company, we get emails a lot from different locations that have relevant data we need for other processes. The problem is that this data is ...
7
votes
5
answers
8k
views
Validate that brackets are balanced
I've done a test for a job (which I failed) and I'd like to know in which ways my code could've been better.
Here are the questions and my answers, it's not very long.
1) Make a program that ...
0
votes
0
answers
86
views
Display a list with (opened and closed) folders
I'm working on a script on Foobar that displays a list of playlists with some of these playlists that can be in a folder (that can be opened or closed). For example:
As you can see there may be 2 ...
3
votes
1
answer
981
views
Adding classes from a given array or an object
I want to add classes to elements based on a source array or object.
For example, it can be:
...
1
vote
1
answer
109
views
Stream Implementation In JavaScript
I usually do not create Streams, but it seems that JavaScript doesn't have a built-in one and I figured I would do it for a personal project I am working on. This code seems to work as intended and ...
4
votes
2
answers
3k
views
Download entire localStorage as file
I would like to download the entire contents from localStorage to a json file (in a "clear" formatting).
I've tried this and it works perfectly. However, ...
2
votes
2
answers
919
views
Clone Div and change input control
I am using keypress to get all the events of a input control. Once the user hits the enter button after I am then clone a div and update the ids. One project I am having is that I only want to do this ...
1
vote
1
answer
391
views
adding characters on mouseover using Svelte
This is my first time using svelte. I am also using tailwind and astro but that is irrelevant. The following component prepends >> to my text when it is ...
2
votes
1
answer
171
views
Command handlers in node.js
Description
This javascript code uses tmi.js to listen for chat messages in a Twitch chat and perform certain actions depending on their content. In the sample code ...
1
vote
1
answer
134
views
Transform an array into object and set index for an unique key in javascript
I have a method that merges keys and indexes from an array into an object.
I'm stuck with ways to compress this method, and I don't know what I can do to make it simpler.
Goal
get an array of objects ...
2
votes
1
answer
76
views
Helper functions to get, set and remove from Firefox browser storage. Also, to get, push and remove from lists stored in the database
I am making a plugin for Firefox, this is (more or less) my first time working with JavaScript. Is this a reasonable design for working with both values and lists in a database?
...
2
votes
1
answer
247
views
Display WordPress Custom Post Types with ACF-Fields on a Google map
I am currently working on my first WordPress plugin. I display custom post types on a google map with pins. The custom post types also have additional information by ACF fields which are displayed in ...
4
votes
1
answer
3k
views
Merge two dictionaries
This function merges two dictionaries, using the value from the later dictionary to resolve conflicts.
I have 5 tests that the program passes successfully:
...
0
votes
2
answers
108
views
Complex statement in typescript get?
I have some get function like this
...
2
votes
2
answers
866
views
Cleaning up nested promises in Cloud function
I am writing the Cloud function for Parse whose purpose is to update my database with a provided array of data objects. The main problem are the nested promises, which doesn't look right. Any help ...
0
votes
2
answers
117
views
How to write repetitive styled components in a cleaner way
I'm using Styled Components for styling and there are many icons defined in the project so in the style file we have this code:
my-component.styles.ts
...
0
votes
2
answers
2k
views
JQuery fixed header that hides on scroll down and shows on scroll up
I am currently working on a site product where I have to create a site-header that is always fixed on top of the viewport but when I scroll down it hides, and again when I scroll up, it becomes ...