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
1answer
97 views

My first ToDo list in JavaScript

I'm new to programming and in front-end. It's really hard for me to learn good practices. Right now I'm trying to learn javascript basics and bootstrap in addition. I did mine first ToDo list with ...
0
votes
0answers
20 views

Fibonacci-Counter implemented with React-Redux

After learning the basics of React-Redux I've made an app to familiarize myself more with the concepts. It's a counter which counts-up the Fibonacci-Number. Here's my code: ...
0
votes
1answer
43 views

Sleep and prolong sleep

What do you think about such an object function? ...
3
votes
2answers
76 views

Data formatting, splitting objects & deleting key's/values

I am quite bad at data manipulation and after a lot of time I was finally able to get it working how I wanted. The thing is I don't like all the delete operations, I think the code can be a lot ...
0
votes
0answers
19 views

Using mobx for a trivial singleton

I'm very new to mobx and unsure, how to use it properly. I'm used to OO, so I prefer using the class keyword and I found myself writing the following singleton ...
0
votes
1answer
46 views

Convert a stream to Promise

I need to collect all the data from the stream and resolve it as promise. I created this stream: ...
3
votes
3answers
106 views

Showing statistics of popular JavaScript frameworks from GitHub API

I am currently working on a simple app to check the stats of popular javascript frameworks. For this I am using the Github API to get certain data sets and have come close to finishing my project. <...
1
vote
0answers
28 views

A Ruby on Rails controller and JS code to add labels to products, like Gmail's labeling tool

My friend asked me to write a tool that lets users bulk add/edit labels (taxons) to store (spree commerce) products. I came up with this, curious to know if you guys find the code readable/...
4
votes
2answers
73 views

Count characters in a string

This code is supposed to count each character in a given string and account for error handling and type casting as well, and it should do it in the most efficient manner possible, with O(n) being an ...
0
votes
2answers
48 views

Simple cube that moves around the container with keys

I made a basic cube that can move around of container and jump too. It's basic but I want to know if I can use better methods, better formatting, or shorten the code. This my HTML: ...
1
vote
1answer
44 views

Request rate limiter

I'm looking for feedback on ways to improve the maintainability and readability of my code. I'm especially interested in hearing about ways I could improve the code's adherence to good object ...
4
votes
3answers
66 views

Take a limited number of items from a potentially infinite generator

Hypothetically, I have a bunch of generators that never end, like: function* progression() { let n = 0; while (true) { yield n++; } } I want to take ...
1
vote
2answers
38 views

Wireframe animation on canvas is slow

I'm recently working on a project that involves animation in the background. It works well on desktop but performance drops drastically on mobile. I'm using Paper.js to import a svg and animate it. ...
2
votes
1answer
27 views

Note Tool - Fill text box with template

I've been working on a note tool for my company to help streamline verifying and noting accounts. I've added in extra features that help with different aspects of the job as well. I'm wondering if ...
2
votes
2answers
48 views

Construct an 2D array of contiguous elements comparing master and incident arrays

Requirement: Based on mainArray which contains the master list of items, and compArray which has items of interest; construct a ...
1
vote
2answers
46 views

Replace string of class of button by class so that only one button is filled in using bootstrap buttons

I'm using bootstrap buttons, and in this case I have 5 different buttons with 5 different classes. When one of the buttons is clicked on, I want it to be the only one filled in, and the others to only ...
0
votes
1answer
51 views

Preparing form data for a POST request with fetch

Acquiring a form’s data for asynchronous POST requests has been a long-standing problem. There is the FormData API, but there are still some obstacles when the form’s data is encoded as ...
3
votes
1answer
36 views

Cancelling ongoing http requests when next one is started - web app search feature

This piece of code is aimed to cancel any ongoing search requests sent from the web application if next request is started, e.g. after user updates the search term. I tested it in the final ...
5
votes
2answers
52 views

Simple function returning 1 if the Mean = Mode, or 0 if not

I'm trying to get better at javascript and have built a simple function that returns 1 if the mode is equal to the mean, and 0 if not. You can enter an array of numbers into the function: ...
4
votes
1answer
131 views

Node.JS Server Queue Processor

I implemented a simple queuing system for my Node.JS app and wanted a critique on it's structure. ...
2
votes
2answers
48 views

Minimizing duplicate routes index.js

I am trying to build a REST API with express router, which contains of nested sub routes. I have mounted these sub routes in my index.js file. I have defined it as ...
2
votes
1answer
51 views

Find palindromes in circular rotated string

I'm trying to tackle a programming challenge to determine how many palindromes exist in a given string that is being rotated character by character. My solution works, but it's too slow, and I'm ...
1
vote
1answer
34 views

Vue.js Stoplight app - Dynamically changing classes on elements

I recently started delving into Vue.js, and decided to try my hand at some custom class/style bindings, so I made a small app that's supposed to cycle through each "light" of a stoplight (red, yellow, ...
1
vote
4answers
221 views

Function to determine the direction of an arrow

I have a function in a project that I feel could be written better. The purpose of the function is to return the direction of an arrow based on two parameters. ...
0
votes
0answers
16 views

Selecting rows on condition in a table

I have a table with courses. The user that is currently logged in can mark these courses as attended and unattended. There can be multiple rows selected. The logic for this row selecting looks like ...
2
votes
1answer
39 views

VueJS ReST Client: Vuex Store Methods

I'm writing a ReST API Client Tester using VueJS. I'm trying to have a really clean code, But I feel like it's too much, Here is my store.js file, which I use it ...
0
votes
2answers
35 views

Using for loops create new object with other objects with matching id's

I'm not sure if this is the best way to write this code.. ...
4
votes
0answers
57 views

JavaScript canvas Snake game

This is my 3rd JavaScript canvas game. It's basically just snake right now but I am planning on adding some more aspects to it soon. I was wondering if I could get some feedback especially on how I'm ...
0
votes
1answer
44 views

Return the first word with the greatest number of repeated letters

I'm learning JavaScript and have written a function that accepts a string and returns the first word with the greatest number of repeated letters. For example: Input:"Hello apple pie" - Output:"Hello"...
2
votes
0answers
26 views

Sort ascending/descending functionally

I've been trying to get into functional programming with javascript and have tried to make some experiments with currying and function composition. What I've played with so far is a sorter function ...
0
votes
1answer
39 views

fetch() with status code checking and re-routing

In examples for fetch() I don't see many example for status code checking. (1) I'm expecting to catch 403 unauthorised responses and push the login path to React ...
1
vote
0answers
67 views

Splitting jQuery code into reusable modules [closed]

I am in the middle of php app development with some addition of js. Since my JS knowledge is not particularly good, I rely on jQuery. However, I like to work with reusable code rather than spaghetti. ...
4
votes
1answer
41 views

Format travelers with correct data

I have a test that I've already turned in but would like some outside review on where I could improve. Spent most of the day today trying my best to keep this O(n) ...
3
votes
1answer
78 views

My first JS program - Tic Tac Toe game

I just completed some beginner web-dev courses (cs:50 and such) and wanted to try my skills. The CSS centering - ugh I just gave up on that, I wanted to make it responsive and the letters centered ...
1
vote
0answers
32 views

Document distance in JavaScript

I am looking for the fastest way to find document distance. How can I improve this? Split each document into words. replaceAll() is faster than replace() ...
1
vote
1answer
45 views

Turning nested jQuery Promises into flat code structure using .done() and .then()

This code uses jQuery promises in combination with callbacks does the following: Saves Group UUID to server using storeGroupOnServer() Creates a DOM element for ...
1
vote
2answers
40 views

A function that generates arrays of video thumbnails using canvas

I have just finished my first version of a function that returns an array of video screenshots created with canvas. What I am looking for are ways to improve this speed by as much as possible. I want ...
2
votes
3answers
90 views

Extracting data in ES6

I have this array const idArray = ["12", "231", "73", "4"] and an object ...
2
votes
1answer
76 views

Image carousel with jQuery 3.3.1

I'm trying to make a carousel with jQuery and I want to know, how to simplify the code further? so... this is my code: ...
1
vote
1answer
42 views

Turn a list of words into a dictionary

I am looking for a way to turn a list of words that may have duplicates into a dictionary/map that counts the number of occurrences of words. After spending some time with the problem, this seems to ...
1
vote
1answer
84 views

Unidirectional Bootstrap 3 carousel

I am working on a custom Bootstrap 3 carousel, with vertical, unidirectional, slide transitions. I want to prevent slide transitions from overlapping when the bullets are clicked in random order and ...
2
votes
1answer
102 views

String compression algorithm using functional JavaScript

I've written an algo to compress a string eg. aabcbbba to a2bcb3a I'm pretty new to functional programming, I feel it's easier to debug and learn from functional code if you're good at it already, ...
0
votes
1answer
26 views

Implementing carryless multiplication using normal multiplication

In carryless multiplication the partial products are XORed (ie addition without carry) together rather than added normally. The partial products themselves are still the product of a power of two (...
0
votes
1answer
37 views

Is this a good way to use Try catch? [closed]

I'm new to handling errors and am not sure how to do it, basically, in a speicific request err.code === 11000 is not actually an error, but expected behaviour. I ...
6
votes
3answers
465 views

Compute count of unique words using ES6 sets

I have written a function which counts how many unique words are included in a given text. The source-code: ...
-1
votes
1answer
73 views

Simplify JavaScript collision detection with offset

I am working on a background project that is a little interactive. Now I am using some collision detection to draw some lines and stuff. The code I have works great but it is very bulky and hard to ...
1
vote
1answer
52 views

Drop-down selectors for state and city

I have this old code and I want it to be easier to understand. Originally, it loaded using an onload on the opening body tag, so I managed to change that to a window.onload, but now redundant code is ...
0
votes
1answer
61 views

Checking if an array element exists in a JS object

I have a feature in my application that should allow users to select items in a drop down menu and move them up and down. Once they select and click on the button I have to loop over the array of ...
3
votes
0answers
55 views

Override prototype inside of constructor of ES6 class for dependency injection

We implemented a small dependency injection mechanism which we use in our project. Now after 2 years of developing our project we need our classes to know who instantiated them via dependency ...