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.

Filter by
Sorted by
Tagged with
1
vote
0answers
9 views

Manipulate urls with regular expressions instead of the slip approach

Basically I have an url which looks like this structurally speaking: http://www.my-site.com/topic1/topic2/topic3/topic4/topic5 and I want to do 2 things to it: <...
1
vote
0answers
14 views

Customizable unidirectional questionaire in javascript

I wrote the below answer for the following question on SO a couple of days ago, and I was curious if the usage of the generator function is an acceptable one. I choose the generator function, because ...
-1
votes
0answers
9 views

This code toggles between two classes when the page scrolls [on hold]

As soon as the user scrolls the notScrolled class is removed and the scrolled class is applied. It works but seems like it could be more concise. Any comments appreciated! ...
-1
votes
0answers
16 views

duplicate Text field validation in java script [on hold]

I have multiple rows, created dynamically on tab press, want to validate duplicate string doesn't allow in text field. ...
4
votes
0answers
39 views

Mapping abstraction? (Node JS) [on hold]

There will be a huge object mapping (transforming) with a lot of calculations and logic for some fields. I would like to refactor this to classes or some kind of separation so it will be easily ...
1
vote
1answer
21 views

Loading KML files into leaflet Javascript map

This is working code for input KML files into leaflet map ...
5
votes
3answers
305 views

Wrap a js function with a fixed this arg

If I use node.addEventListener('click',Wyg.Editor.nodeClickedEvent); then when node is clicked, ...
1
vote
1answer
37 views

Recover a secret string from random triplets

Got this problem from Codewars. There is a secret string which is unknown to you. Given a collection of random triplets from the string, recover the original string. A triplet here is defined ...
-1
votes
0answers
10 views

Leaflet search plugin fetched by $GetJSON function [on hold]

I have been fighting with running the leaflet plugin with $GetJSON function My code looks like this: ...
3
votes
1answer
33 views

React.js hook to move a car on a 5×5 board

I've got this custom hook that is suffering from a bad case of violation of SRP This is a simple 5x5 board where a car can move around. Together with a server side check if the move is valid or not. ...
8
votes
3answers
632 views

Weapon class firing logic in JavaScript

I'm making a program to compare Borderlands 3 weapon damage over time in a graphic. There's still some work to be done, like implementing elemental damage, but I'd like to know if I'm doing a good job ...
0
votes
0answers
13 views

Polling an SFTP server to list files in a directory

When is it better to instantiate the sftp client globally vs inside a function as shown below? What considerations favor one method over the other? For a long ...
5
votes
0answers
52 views
+100

“Block a website” script with vanilla JavaScript

I use this script to block access to a one or more websites with vanilla JavaScript. I find that it helps me avoid some addictive news websites that make me depressed. (Credit to Marat Tanalin for ...
5
votes
2answers
54 views

Dropdown menu that opens on click using plain Javascript

I made a simple dropdown menu which opens when clicked, and closes when the user clicks anywhere outside the menu. The following is the codebase: ...
1
vote
0answers
20 views

Promise-based AJAX calls base class

I am more than willing to use both a Promise library and an AJAX calls one if the situation calls for it. This base class sits at the very bare bones of my system and it needs to be done right. My ...
4
votes
2answers
99 views

An ES6 array of numbers - Double last number, delete the first number

I'm writing a JavaScript function for an array, based on a geographic sequence. \$[1, 2, 4, 8, 16]\$, etc. This function needs to populate the next number in the sequence $$item_n = item_{n-1} * ...
0
votes
0answers
29 views

How can I refactor my code for this coding challenge [on hold]

I have finally complete the cash register challenge found on freecodecamp.org and I was wondering how I can further clean my code. I need help refactoring my code. Link to challenge here: https://...
7
votes
1answer
51 views

Find neighboring PINs on a numeric keypad

I am new to coding and to apply for an internship I need to solve several tasks. This is one of them. I wrote working code, but the program says it takes too long to complete. Help me speed up my code ...
2
votes
0answers
22 views

Fulfillment webhook with Dialogflow to operate on a Firestore database

I'm currently calling a fulfillment webhook with dialogflow in my node backend, performing crud operations on a firestore db. Is there a better, cleaner way to ...
-3
votes
0answers
23 views

Creating a new item instance only if two objects have different signatures [closed]

When adding to a list of products, I need to only create a new instance of a product of type A only if the incoming entry has at least one variable with a different value from the one already in the ...
0
votes
0answers
34 views

pick interesting properties from a js object

Utility functions, similar to Lodash.pick but it also picks beyond level 1 and inside arrays. Useful for offline storage of big objects we want to skim. An interactive version of this code, with an ...
3
votes
0answers
48 views

Resolving Git conflicts with Javascript

Challenge: Resolve git conflict by resolveGitConflict(linesArray, resolveMode), where linesArray is an array of strings ...
1
vote
0answers
18 views

Callback usage with custom Stack Exchange Flair, is it difficult to follow?

So today I decided to continue refining my JavaScript skills and utilized the Stack Exchange API (v2.2) to write a "user flair" replica. In case you don't know what the flair that SE provides is: ...
5
votes
4answers
1k views

Confirm the ending of a string

Challenge: Check if a string (first argument, str) ends with the given target string (second argument, target). This ...
7
votes
2answers
140 views

eCommerce Mockup App in JS

I have completed this mockup eCommerce app using Javascript. This version can add products into a shopping cart and automatically calculate the order summary in the shopping cart. It can also delete ...
0
votes
0answers
26 views

Store tweets to a local MongoDB server

I use NodeJS along with the MongoDB NodeJS Driver to store tweets into my local MongoDB server. In the following setup, mongos insertOne method gets invoked quite ...
2
votes
1answer
92 views

kryptein cryptography package for Node.js

I have written a cryptography NPM package called kruptein. The code is also hosted on GitHub. Having used multiple "best practices" with regards to key management, algorithm selection, key size, iv ...
6
votes
1answer
99 views

Simple input class change with vanilla JS

I am just testing how I solved simple stuff. Goal: The aim is to expand the width of an input and collapse it. When mouseover ...
6
votes
0answers
81 views

Nested cross-origin iframes for secure user-configurable javascript tools

Context I'm trying to build a system in which a tool (the Client) will generate a header to be used as part of an HTTP request from the user's browser. The user should be able to choose their own ...
3
votes
1answer
44 views

Making a grid for collision detection in a game that wraps

I'm making a 2D game which wraps (when you move off the right edge, you appear on the left, etc). The game area is square, all objects are circles (with AABB smaller than the game area, and in most ...
7
votes
2answers
125 views

Webpage with a preload animation using JavaScript setTimeout

I am working on a website with an animation that runs at the beginning before the content of the homepage becomes visible. I've looked at some examples of preloaders and now use that code with some ...
1
vote
1answer
43 views

Browser quiz game

I have made a little game in JS. Are there any remarks? The game asks a question through the console and accepts the answer through prompt. If the answer is correct you'll get points. To stop the game ...
1
vote
0answers
45 views

eCommerce Mockup App in Vanilla Javascript [closed]

I have completed this mockup eCommerce app using pure Vanilla Javascript. This version can add product into shopping cart and automatically calculate the order summary in the shopping cart. It can ...
3
votes
2answers
45 views

Async Data Validation with Hooks

I've created a component that validates an email address. It works, but since I'm new to hooks I would like some validation of what I've done before I let what I've done loose on the rest of the ...
2
votes
0answers
21 views

Fast algorithms in Javascript for shortest path queries in directed unweighted graphs - follow-up

(See the previous iteration.) Now I have reworked my pathfinder program, and I ended up with this: ...
1
vote
0answers
20 views

Using ReactJS. Div changes color on hover. On Click drops down description

Hi I have a ReactJS component that I feel is a little bulky. The component holds the information for an event, and clicking on it shows the description for the event. Clicking the event component ...
1
vote
1answer
35 views

Join a JSON object of arrays and reduce down to one key [closed]

Given that I have a dataset as follows: { 1: ['Extremely Tall'], 2: ['Tall'], 3: ['Medium', 'Low'], 4: ['Dwarf'] } and I receive a value (e.g. Tall or Medium) I ...
7
votes
1answer
89 views

Generating a chess board with JavaScript

In another attempt to further my knowledge in the JavaScript language, I've written a chess board generator that will essentially create a chess board with any initial state supplied. This supports ...
0
votes
1answer
47 views

The Game of Pig in JavaScript

I've implemented the game of Pig in JavaScript. My implementation has the following rules: Two players take turns playing in rounds. In a round, the player rolls a single die as many times as they ...
4
votes
1answer
56 views

Making basic physics object class

I'm creating a 2D game in JS, and I've made the generic class that all objects in the game will be (I've decided they are all circular for now). An object has ...
3
votes
0answers
51 views

Fast algorithms in Javascript for shortest path queries in directed unweighted graphs

(There is a follow-up question available to this: Follow-Up Question) So I have this: ...
1
vote
1answer
51 views

Automatically select the table rows between two selected rows

The code is to check the rows in a table. If in a table two non consecutive rows are checked then all the in between rows should be selected by itself. Also, after selecting two rows, on selection of ...
0
votes
0answers
24 views

Is my ShoppingCart library correct according to SOLID principles?

I have recently created a simple shopping cart library. But I have to be sure about, is it solid or not. If not, then what do I have to do to improving my code base?. ...
1
vote
0answers
18 views

Providing JavaScript Configuration (Laravel config() style)

This may be better suited on Stackoverflow, in which case, please let me know and I will move it over... Background Consider the following file structure: ...
4
votes
2answers
49 views

Wrap array operation result string inside another string

I'm trying to loop through an array, add " before, ", after each member but ommit the , at ...
2
votes
0answers
35 views

Ensuring a valid JavaScript string in security-critical application

I'm writing an application where users can write custom expressions which are then converted to JavaScript functions and executed. The expressions are used for filtering and sorting data from a ...
1
vote
1answer
60 views

Toggle between two options in an object?

I have just written this code for toggling between two possible states of an object. ...
2
votes
1answer
36 views

Counting the number of alerts by type and partition from a JSON object

Here is my problem, I receive these kind of json data and I don't know in advance the keys (unknownProperty#) but the different objects in this data array have the same keys. What I need to do is to ...
1
vote
0answers
20 views

How to splits blade files that contain javascript?

I have these scripts ...