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

JavaScript change calculator

I'm new at coding and I'm learning it on freeCodeCamp, that's the most hardest problem that I have already do at that site. After finishing it (after I vibrated as if I had won a world competition of ...
1
vote
1answer
44 views

Recursively unpacking a javascript object

I'm seeing a React course, we were studying fundamentals of javascript for a while. We saw how to access the content of an object and display it in console. My solution for the problem of displaying ...
1
vote
1answer
28 views

Convert string to object array javascript

I want to convert string to object array. Suppose I have following string. const str = "someValue,display"; I want to convert it like following. ...
2
votes
0answers
36 views

JS icons animation

I've written a simple JS that takes care to animate an icon. At first I wrote it quickly and without paying attention to any kind of optimization: ...
0
votes
1answer
79 views

How to create an array with 10 elements based on a maximum value [closed]

I got a number that can range be either 10, 20, 30, 40... up until 100. I'd like to make an array from that number. The array should be structured as follows: If the number is ...
1
vote
0answers
46 views

Bad performance of a Graph Algorithm

I implemented a solution for the problem below, but its performance is not good. I know I can find the solution online, I'm trying to understand what is causing the bad performance in ...
2
votes
0answers
29 views

Node.js Dumbserver

Dumbserver, or the simplest workable HTTP server. It is supposed to operate in the 'traditional' way, that is, mapping paths in requests to the directory structure. Why did I write it: I needed a ...
-1
votes
1answer
77 views
1
vote
3answers
99 views

Replace array values with product of all other values

Need help to optimize the following code for lower time complexity: ...
4
votes
3answers
106 views

Creating a binary word search 🔍

I recently crafted a binary word search puzzle using HTML, CSS and JavaScript to dynamically build grids within a grid: ...
2
votes
1answer
40 views

Draw triangles on the HTML canvas optimization

There is a function that draws triangles on the canvas area in each lines: ...
0
votes
0answers
41 views

Create a new array of an array of numbers and an array of objects whose key is used for search

I have an array requestArr in which there are objects with two values, also I have an array with objects itemsArr keys which is '...
0
votes
0answers
28 views

How can I call React useRef conditionally in a Portal wrapper?

I am attempting to make a simple Portal wrapper that does the following. Can render multiple portals on the same view Can render multiple portals by targeting parent ids. This cannot be done by ...
0
votes
2answers
46 views

Build list of prefixes, including the whole string

There is a string "abcdebfkj", we need to transform this string to the below array: expected o/p:   ...
0
votes
0answers
34 views

Single incrementCounter for 2 form submissions

Everything works perfectly fine. However, I just want to know if there's a way for these codes to be shorter and non-repetitive and how? I have these increment counters to update the stocks after ...
0
votes
0answers
35 views

Random sample items for testing

This function (in a React web application) code takes a random sample of items to test in each test function, for end-to-end testing: ...
1
vote
0answers
38 views

Codewars: Path Finder

Task You are at position [0, 0] in maze NxN and you can only move in one of the four cardinal directions (i.e. North, East, South, West). Return true if you can reach position [N-1, N-1] or false ...
1
vote
0answers
25 views

Small JavaScript function that mimics flag handling of the command line

I am writing a function that I would use to handle parameters with options for use later in another project. A sample input would be similar to this: ...
0
votes
0answers
36 views

Calculator with vanilla procedural JavaScript

I am doing a project for a calculator in JavaScript. Here is the project GitHub page: https://github.com/florinpop17/app-ideas/blob/master/Projects/1-Beginner/Calculator-App.md Demo: https://...
0
votes
0answers
13 views

Set cookie once modal opens on page scroll

So I am still learning a lot of things and wanted to see if someone wanted to look over my code and tell me if there are ways to improve things and maybe make the code a little cleaner. Here is what ...
0
votes
0answers
21 views

Setting a complex component via useEffect and useState?

I have a component that I am updating from running a plain function on every render, to one that only runs when some components update: ...
2
votes
2answers
40 views

Implement complex, intersecting limitations on when and when not to log [closed]

It is a classic problem to handle ever changing requirements in a cleaner way without using too many nested if statements. Here is my current code in JavaScript. ...
6
votes
2answers
98 views

Calculator with JavaScript

I've just created a fully working calculator for my portfolio, and I would like to get a code review. Does that code looks good, or maybe I should refactor it? Is it good enough to be a part of a ...
0
votes
0answers
14 views

Stopping WOW.js animations from happening when the element is positioned before the current scroll position

I have been using WOW.js to animate my elements for some time now. I've noticed that when a page visitor reloads the page, animations that have already "been scrolled into view" by the ...
0
votes
0answers
22 views

Class for handling key/mouse inputs

I'm writing an html5 canvas game for the first time. To start with, I decided to make the below class so I can check for inputs every update loop. The class can detect key/mouse down/up events and ...
1
vote
1answer
26 views

Find coordinates of neighbors out of given coordinates

I'm programming a checkers game in typescript. I'd like to explain some important details to understand how the following code works. In my game coordinates are a string, like "b4". I want ...
3
votes
0answers
23 views

Fetching data from endpoint, retrieving coordinates, then merging into an output

I'm in no way a skilled developer (or even a developer at that!) but I did want to take a go at writing a script that fetched one endpoint's data, extracted some data, sent if off to be geocoded, then ...
0
votes
1answer
93 views

Regex detect URL without http(s):// and www

I want to locate urls without protocols in the text, and then add the protocol before them. This means I don't want urls that begin with http(s):// or ...
0
votes
1answer
20 views

Function pattern for running DB queries using pool or transaction

Take the following INSERT query. Using knex (JS) just for abstractions ...
0
votes
0answers
18 views

Skill section with flexbox and javascript. Clicking on certain skill will change the summary

It's the first thing I've created using flexbox and Javascript so I feel like my code could probably improve a lot. Any feedback would be greatly appreciated! https://codepen.io/dee91/pen/jOwbQmd html:...
2
votes
1answer
73 views

Todo App with JavaScript

I am learning JavaScript and this is a simple todo application I made which uses local storage. It is currently running at: https://koraytugay.github.io/vanillatodo/#. The code is as follows. I am ...
0
votes
1answer
37 views

Is there any way to make my JavaScript code more logical and efficient? How to convert functional to OOP in JS? [closed]

I created some tooltips using javascript but after writing the code I found it a lot more complicated and hard to read/understand is there any way to shortened my ...
1
vote
2answers
113 views
1
vote
1answer
69 views

Best way to cherry pick objects from array of objects

With this data I am returning one object per keyword prioritising preferedDomain string on domain and then its higher ...
1
vote
1answer
56 views

How can I rewrite this typescript map to be more concise?

I have a short bit of TypeScript code that looks like the following: ...
1
vote
1answer
61 views
0
votes
0answers
30 views

More efficient webgl animated color interpolation?

The code below creates an animated, four-cornered gradient with vertex and fragment shaders in WebGl. When I run it in the browser, the fans on my MacBookPro (2.2 GHz Quad-Core Intel Core i7 with ...
0
votes
1answer
107 views

Fisher Yates Shuffle, but using Javascript Array Functions

I have been looking at the Fisher Yates randomizing suggestions on StackOverflow after ruling out arr.sort(v => Math.random() - 0.5) due to lack of randomness in ...
2
votes
0answers
38 views

Combining columns based on header names of an array

PROBLEM: I need to merge the columns by identifying the headernames and they work as desired by using the below code. The code is very inefficient as I am using an eval to accomplish the job and I ...
0
votes
1answer
64 views

A Java EE7 web application for counting views in a static HTML page

I have this blog lurking around in the web. It's just static HTML, but I was interested to keep track of all the views on that blog. Finally, I end up with the following web application: (The Java ...
2
votes
2answers
67 views

Complex Filter in one Opration

I am working on a Data-based application. I wrote a code to filter the table. The table has String and Numbers. I some filter ...
0
votes
1answer
41 views

My Theme Switcher App has a need to be criticized

I am a student who wrote logic to theme switcher, but I don't know if everything is ok. I want professionals to estimate my code and will say what is probably mistaken. I accept all recommendations ...
0
votes
1answer
38 views

JavaScript Deck Builder: Build Deck, Draw Random Card from Deck

this is similar to another project I did here: JavaScript Deck Builder: Shuffle, Draw Cards Except this script does not shuffle or draw cards from the top of the deck. Instead the script builds a deck,...
2
votes
1answer
111 views

Create random wave forms using JavaScript and CSS

Desired output: Animate the wave forms, but use less resources. Any bugs: There are no bugs that I know of. I tied searching google for "use less setIntervals in my project" and found this ...
0
votes
0answers
28 views

JavaScript Deck Builder: Shuffle, Draw Cards

I'm looking for critiques or different ways I could approach writing a deck builder script. I wrote script to shuffle a deck of cards, then draw cards from the top of deck, drawn cards are then ...
0
votes
0answers
22 views

Memory Allocation problem in codewars: Improvements to use less memory : Tribonacci sequence

Consider my following code from the Tribonacci sequence kata. ...
0
votes
0answers
59 views

Conway's Game of Life written in JavaScript

So I'm staying up for 24 hours watching Le Mans and decided to write something fun. I wrote an implementation of Conway's Game of Life (information here if required). All feedback is welcome (...
0
votes
1answer
53 views

Hackerrank Gridland Metro - using Interval Cover Solution

Hi there I was hoping to get a better grasp of greddy algorithms while trying to solve this problem: Hackerrank: Gridland Metro and I was trying to apply an algorithm where each grid could be ...
2
votes
0answers
33 views

How could this indentation-based lexer be simplified?

I finally got this lexer working. How can the parse function be simplified? The goal is to take a tree of indentation-based text, and convert it into parentheses-...
5
votes
3answers
431 views

Refactor JavaScript nested if-else

I'm really new to code optimization and JS. I would like to ask for help on optimizing my code. Thank you in advance. Here is my code: ...