Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [javascript]

ECMAScript or ES (commonly referred to as JavaScript) is primarily used for scripting web-pages but also has several embedded forms as stand-alone interpreters or JIT compilers. Use this tag for questions regarding all versions of ES up to the current ES8 and its dialects / implementations: JavaScript, JScript, etc., excluding ActionScript.

2
votes
3answers
98 views

Find the greatest common divisor of n numbers

Just had this as a practice test problem and I'm curious how to optimize for performance. Thanks! The greatest common divisor (GCD), also called the highest common factor (HCF) of N numbers is the ...
2
votes
0answers
34 views

Simple table sorting using plain Javascript

This is a simple and clean script for sorting a specific column in a table. You could edit and parametrize it to add more customization, but I wanted to share the base concept. Base concept (I think ...
1
vote
0answers
14 views

JavaScript code for MAC registration micro webservice

The following code is part of the front-end of a micro webservice for users to allow them to register MAC addresses of their network devices and administrators to enable those and to generate a ...
0
votes
1answer
42 views

Interweaving an array's values

I've written a function to sort an array that interweaves an arrays values in the way of if you had two separate arrays [1,2,3,4,5] on one side and [6,7,8,9,0] on the other and it becomes [1, 6, 2, 7, ...
-1
votes
2answers
54 views

Two-sum solution in JavaScript [closed]

I was given this question during an interview. It is similar to two sum problems and I would like to ask for feedback for my solution. Merging 2 Packages Given a package with a weight limit ...
0
votes
1answer
24 views

Authentication using express-session

I'm making an online shopping store or e-commerce and I use an express session for many things. Example: Shopping Cart, Authentication user* I store the data chart list in the database based on the ...
0
votes
0answers
19 views

Manage show state of Modal component from inside of component

I work on React apps on my spare time. I try to leverage the concept of HOCs and component reusing. I have some components where I have a form, and I created a component for showing a modal, for ...
1
vote
1answer
55 views

Copying text to the user's clipboard

Here's my code. ...
2
votes
1answer
40 views

Create a separate JSON + syntax

My code already works perfectly. Here is the JS file: ...
2
votes
1answer
50 views

Tip Calculator in pure JS

A simple tip calculator that asks for the total bill amount, service quality (used to determine what percentage of the total cost will be tipped), and how many people are sharing the bill (used to ...
0
votes
0answers
59 views

Time limit exceeded on HackerRank “Username Disparity”

Here is the hackerrank question: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of ...
0
votes
1answer
44 views

On form inputs focus, show div. hide div on blur for multiple inputs and hidden divs

I posted a question on Stack Overflow and got an answer that works but has a lot of duplicated code. In the future, the functionality may also require a third or more divs to be shown or hidden. The ...
1
vote
1answer
46 views

Generating a table based on an array of objects

I have a React component that generates a table based on an array of objects, which gets populated with data in an object. I'm trying to learn as much as I can about React.js / JavaScript. Could ...
2
votes
1answer
72 views

Shuffle deck of cards in JavaScript

I know randomness in programming can be a deep topic, and searching the topic seems to result in Fisher-Yates being the best method, but I'm curious what people would say about this method. Basically,...
0
votes
1answer
33 views

Changing the text of a few elements when a tile is clicked

I have created a basic web page that contains a panel which displays some details about an object, and a panel which contains some tiles that are used to choose which object to view. The idea is ...
1
vote
2answers
52 views

Check whether an array can be the result of merging two smaller arrays, maintaining order

I'm prepping for a tech interview coming up and trying to have a better understanding of what I should look out for in writing code. Also, feel free to correct the terminology that I use as I want to ...
0
votes
2answers
51 views

javascript - consolidate multiple null/undefined checks [closed]

My brain is fried from looking from looking at this for so long. Is there a more efficient way to do this code block. We have the ability to use es6 code too if that helps. First it tries to set ...
2
votes
1answer
64 views

Toggling Strict mode in JS

I made this code because, I figured that it might be an interesting concept, and that it would be nice to see it work. It enables the toggling of strict mode in any string of code. It even allows you ...
1
vote
1answer
65 views

Leetcode Longest Common Prefix

I just recently finished the following problem on Leetcode problem. I know it's not the cleanest or fastest solution. I would appreciate if I can get some feedback on how to optimize the code. The ...
2
votes
0answers
52 views

Python/Django Class based saving

I'm creating multiple Django apps with vote possibilities, so I made an app vote to handle all this votes. In my templates I'm including an ajax-function named <...
3
votes
1answer
40 views

Debouncing function, ES6 version

Please, review the code: ...
1
vote
1answer
38 views

Redux: button click potentially fires 3 action for different reducers

I’m using Redux and thunk, I have a list component ...
1
vote
0answers
40 views

Javascript Call To Action Modal

I created a simple modal that when a user scrolls down a blog post, a modal pops up. If the user wants to sign up for newsletter, then a form pops up. The only external library I used was body-scroll-...
0
votes
2answers
46 views

JavaScript Etch-A-Sketch implementation from The Odin Project

I'm working through the curriculum at The Odin Project. I recently completed the Etch-A-Sketch project and am looking for some help/feedback regarding my code. Specifically, I feel that the functions ...
0
votes
2answers
59 views

JavaScript ES6 import / export

I am experimenting with JavaScript ES6 import and export and wanted to achieve the following: Use the import / export style of including JavaScript files. Import a class file and create an instance ...
1
vote
1answer
62 views

Basic orbiting planets in P5.js

I started studying JavaScript about a week ago and I would like some opinions and advice on my code. This program just creates a canvas and instantiates 5 planets that orbit around a sun, giving them ...
0
votes
0answers
15 views

D3v4 force layout transition from clustered layout to one node

I was wondering if I could get some input on how to make my code more concise, since I think in particular with the force simulation sections I have some repetition. And any other input to make my ...
0
votes
1answer
67 views

Stripe payment form

I have a stripe payment form and when I use different forms that get hidden, I must use separate IDs for the form to appear. I have found a way to do this but looking to simplify the code if this is ...
3
votes
3answers
93 views

fizzbu| - Fizzbuzz with dynamic height

Here is a variation on a theme: fizzbuzz. After providing this answer recently, I decided to practice some VueJS skills with outputting the values and conditionally applying styles based on the value. ...
0
votes
0answers
12 views

Optimizing Datatables table of tens of thousands of client-provided rows

We have this employees table, that looks like this: that contains 16,530 employee rows. As expected, this table takes more than 30 seconds to load. I have been tasked with speeding it up somehow. ...
1
vote
0answers
50 views

ReactJS Typewriting animation

One of the dream idea to build typewriting in ReactJS. The code seems to be working, still there are something looks not that great in the code 😔 Looking for better solution (best practice) in the ...
1
vote
1answer
64 views

Using a public API to display data

It's a simple app that uses a public API to display data. It works as is, but I'm seeing a lot of spaghetti code that my limited experience can't fix on its own. ...
1
vote
1answer
36 views

Efficiently aggregating nested data

Problem Given the following data: ...
-1
votes
1answer
45 views

Evaluating expressions in “case” vs using “if/else if” [closed]

I was just tempted to write a similar piece of code to the one presented in this answer on SO (posted below). The problem is having to discriminate between different cases where exactly one case is ...
1
vote
1answer
51 views

Queue implementation in ES6 [closed]

Here's my Queue implementation in ES6, ...
0
votes
0answers
39 views

HackerRank - Left Rotation in JavaScript

I'm looking to learn more about data structures, time complexity, and efficient algorithms. I have solved the Left Rotation Problem on HackerRank using JavaScript. I am looking to see ways to optimize ...
1
vote
1answer
17 views

Summary page with react-redux: container or presentational component

I'm building a Summary page for merchant activity in a marketplace with react and redux. The application has already a structure where there is a "MerchantContianer" ...
0
votes
0answers
28 views

A better way to retrieve data in firebase using redux

So i want to be able to make the following method inside of componentWillMount more robust, and essentially put this method inside an actions function. Post.js <...
0
votes
1answer
49 views

Experimenting with a OOP design pattern in JavaScript

Initially, I was using the class syntax to structure my code. While it sure did feel nice to work with, I found it lacked some important functionalities, like ...
3
votes
2answers
113 views

Singly Linked List Implementation in ES6

This is my Singly Linked List implementation in ES6. ...
1
vote
0answers
44 views

Sorting options within a select element

I am trying to sort the options within a SELECT element. I wonder if I am doing it stupidly or not, so perhaps someone can look ...
3
votes
1answer
53 views

Leetcode Mountain Array

I've been working on longest mountain in array on Leetcode: Let's call any (contiguous) subarray B (of A) a mountain if the following properties hold: ...
1
vote
1answer
144 views

jQuery Slideshow with pagination

The code below is for a slideshow that shows a slide with class active, pre-loads a slide with class next, and holds the slide with class last in the background. My biggest issue with this is there ...
1
vote
3answers
53 views

Change state depending on holidays, weekends or hour of day

I'm writing a script that's changing the background color depending on hour of day, if it is a weekend or if it is a Swedish holiday. I have a functional script and as I want to improve my programming ...
1
vote
0answers
30 views

Rendering custom components with React Route parameters [closed]

I am not able to render custom components via the Route and 'return' attribute on Route. I'm not getting any errors with my code, so it must be something that I am missing. But basically what I am ...
5
votes
2answers
88 views

Find top two clothing sizes in the array

I was recently asked this question in an interview. Here is the solution I came up with. Please let know if I could have done this differently or in a more efficient manner. The question is as ...
1
vote
1answer
53 views

Zig-zag child element with Flexbox and JavaScript

Recently I found a question on StackOverflow that seemed very interesting: How to make HTML elements "zig zag" this way: ...
2
votes
0answers
16 views

Bookmarklet to quickly fill an input with a maximum width string for visual testing purposes

I'm currently working on a complete overhaul of the CSS of our flagship product with a goal of maintainability and simplification. During the testing, my coworkers and I have found that a lot of pages ...
1
vote
1answer
43 views

Monitoring navigation function: logic judgment

Write a simple monitoring navigation function. I feel logic judgment still needs to be optimized. I don't have a clear idea right now about code logic such as reducing ...
2
votes
1answer
35 views

Wrapping fetch(), preserve promise-based API for outer function

One of my react component's methods is using an async fetch() internally. After fetching the response from the server, it is being converted to JSON, then I perform a check on that JSON string. ...