Stack Exchange Network

Stack Exchange network consists of 175 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.

3
votes
1answer
67 views

Google Custom Search placeholder function in JavaScript

Problem: We have a Google Custom Search function that replaces the input placeholder attribute and it works okay. Would you be so kind and help me with reviewing ...
1
vote
1answer
30 views

Evaluating an arithmetic expression from a binary tree

Let's say I have a Binary Tree that looks like + 2 * 5 8 I've written a function to traverse inorder to solve it as 2+5*8 Is ...
3
votes
4answers
149 views

Calculate inputs average

I'm creating an online calculator to get the average grade of different tests my students take. I wonder if you see any problems in the following code or any way to improve it: ...
3
votes
1answer
43 views

Function to display an alert

It's a user alert script. It worked in every browser I tested. But the function itself looks very messy/repetitive. Is there any way to make this cleaner? ...
3
votes
1answer
34 views

JavaScript that deletes everything inside a folder on Box.com

I just finished a simple script for Node that will delete all the folders and files inside a specified folder ID through Box's API. It works by getting a list of items inside a folder, then generating ...
4
votes
0answers
58 views

Ship placement verification function for Battleship game

I wrote server-side Battleship game simulator in nodeJs/Javascript: A random player who begins is chosen. Both place their ships. Software recognizes if they are placed correctly. One of the players ...
2
votes
1answer
48 views

Function to filter comments and ratings, with pagination support

I have a web component that is rendering a list of items and I have this method for filtering these items based in a filterBy object that is being updated by other ...
3
votes
0answers
53 views

AJAX shopping cart with quantity +/- buttons

I'm a junior developer (couple years into it) and very new to AJAX. I'm writing an internal inventory application built on MVC and right now I'm dealing with adding and removing items to/from a cart. ...
0
votes
1answer
42 views

JavaScript - Difference between two dates in days or less [closed]

I have 2 dates that I would like to have the difference between them in days and if less than a one day simply show "less than a day". ...
5
votes
1answer
78 views

Showing events on a multi room scheduler

I write a web app that shows events on a multi room scheduler. I use VueJS for the first time on a real project. Here, I loop through the events array every room column (two nested v-for). In jQuery ...
1
vote
0answers
194 views

Deepest pit of an array

Following is based on a problem description from a Codility test, as a task in an interview. DeepestPit - problem description A non-empty zero-indexed array B ...
0
votes
0answers
15 views

A XMLHttp Request in the browser

...
4
votes
2answers
85 views

PermCheck Codility

The following code gets 100% on the PermCheck task on Codility. It should be O(N). The question is: A non-empty array A consisting of N integers is given. A permutation is a sequence ...
0
votes
1answer
34 views

Is there a better way to create constants in javascript? [closed]

Isn't there a better way to create my constants that I can use elsewhere in my code ? ...
0
votes
0answers
21 views

Generate HTML file from Handlebars template and data object

I have a class called HtmlFile which has a method called generate. The generate() method is ...
1
vote
1answer
122 views

Embedding an HTML (String) Generated from a Tree Structure JSON

How to make insertJson faster (I should keep the script compatible with old versions of IE and other browsers)? Sorry about my codes that I had to write with short ...
4
votes
1answer
71 views

JavaScript BlackJack Prototype

What would be the best way to organize BlackJack in JavaScript and maybe start with blank slate? Specific areas: Updating UI Incorporating the dealer hand into the ...
2
votes
2answers
47 views

Split an array of items into several arrays, given a condition

The question is very simple : I have an array of items, that all have a date. According to the date, I would like to split this array into several arrays. In my case, I would like to split the array ...
0
votes
1answer
47 views

Temperature and speed unit converter class in JS

This is what I came up with, but I'm not sure if: putting it in Class is the best approach multiple repeats (this.val etc.) are acceptable there is a better ...
1
vote
1answer
48 views

Upload and drag the image inside a mask image

I am allowing users to upload and drag images with this code. Give me a review of this. Codepen ...
5
votes
0answers
69 views

NodeJs crawler for recipes

Here is my try on a crawler made in nodeJs with cheerio, I made it with the idea in mind to use it in a future project I wanna make. Here is the git link: https://github.com/Just4lol/CookCrawler If ...
2
votes
2answers
29 views

Express.js handler to update user fields

I have an express handler which i thought was pretty simple, but CodeClimate flagged this method as having a Cognitive complexity of 6 (5 is the max by default without flagging something) Curious how ...
2
votes
1answer
50 views

Form validation function for React

I need to validate multiple input fields using React. I am using a simple if-else block for each input field but I would like to optimize my code and make it better. I feel there can be a better way ...
3
votes
1answer
57 views

Get two array from array of objects

I have an array of objects: ...
4
votes
1answer
36 views

Searching a nested data structure for 2 attributes

So I have the following data structures ...
0
votes
0answers
58 views

Sandboxing untrusted JavaScript execution by redeclaring variables

Suppose, via AJAX, I downloaded a string jsCode containing JavaScript code from a (potentially malicious) third-party website. I want to allow the code to implement ...
1
vote
1answer
24 views

Activating Lightbox on HTML elements with the has-lightbox class

I'm in the process of trying to do "object oriented thinking", as to improve my code skill. I've the following method that creates a lightbox for every item with the class ...
1
vote
0answers
26 views

Asynchronous retrieval of WebExtension browser history visits

I'm writing a small class that wraps the existing functionality of browser.history.search in Firefox's WebExtensions API. The current API only directly searches for ...
1
vote
1answer
52 views

Turning simple Node.JS Postgres query and logging into most-functionally-pure-possible code

After reading "How to deal with dirty side effects in your pure functional JavaScript," I've decided to take something I do on a regular basis ("Original approach" below)—connect to a Postgres ...
3
votes
2answers
72 views

Use weather API to get information in JavaScript + jQuery

Please can any code experts review and improve my code? HTML ...
2
votes
2answers
129 views

Given a set of closed intervals, find the smallest set of numbers that covers all the intervals

The Task: Given a set of closed intervals, find the smallest set of numbers that covers all the intervals. If there are multiple smallest sets, return any of them. For example, given the ...
1
vote
1answer
48 views

HTML5 canvas video with React

I'm trying to work HTML5 canvas video into a React application while making the code as clean as possible. What kind of improvements should be made to improve the performance utilizing the React to ...
2
votes
2answers
39 views

Iterating through two objects with different structures in parallel

I have two objects, one input = Array<Type> and one stored = Array<{..., Type}> What's the best (cleanest) way to ...
4
votes
1answer
46 views

Select members based on activity

I was asked by a friend to write a simple page for selecting members to various tasks. The members are listed in a textfile, along with how much they are willing to contribute (Usually a number ...
4
votes
2answers
78 views

square the elements of a sorted list and give the output in sorted order

Given a sorted list of integers, square the elements and give the output in sorted order. For example, given [-9, -2, 0, 2, 3], return [0, 4, 4, 9, 81]. My solution 1: ...
1
vote
1answer
51 views

XMLHttpRequest in the browser

The intention is to implement an xmlHttpRequest in plain vanilla js while considering all possible errors and problem situations without crashing in the browser. Result and faults are to be properly ...
1
vote
1answer
29 views

JavaScript shortcut to create elements

I've created a personal API for creating elements for an HTML page. I would like feedback on efficiency, particularly in creating buttons and labels. Any and all feedback is appreciated and considered ...
3
votes
2answers
44 views

SRT caption support for HTML5's video element

With HTML5 you can add captions to your video using the <track /> element. However, only vtt files are officialy supported, while the current most populair ...
5
votes
3answers
69 views

Print out N by N Spiral Matrix in javascript

I got this question during my practice interview. Matrices - N Spiral Matrix Prompt Given an integer N, output an N x N spiral matrix with integers 1 through N. Examples: ...
1
vote
0answers
23 views

Javascript router for React with hooks

So I am learning hooks and context, and I wanted to make a simple router. I wanted a simple API where you can just pass in routes. initialRoute should be optional, ...
1
vote
0answers
30 views

Spawning multiple child processes to preview Vue.js projects

Context: I'm making a Codepen-like app but I want it to support sophisticated JS libraries/frameworks like Vue or Angular 2+ for example. I want to have a live preview of my snippet which updates in a ...
10
votes
2answers
143 views

Javascript cron-to-human-readable translator

I'm developing a webpage displaying the scheduled pipelines from all projects of a GitLab instance. The scheduled time is expressed using CRON expressions, i.e. five digits as follows: Because not ...
1
vote
0answers
44 views

Parsing potentially nonexistant JSON fields in JavaScript

Context: I'm currently toying with the Google Geocode API to break down address strings into a more machine-friendly format. The problem is that neither the user input or API output are 100% ...
1
vote
1answer
60 views

window.innerWidth - workaround for when it returns the wrong value

Some JavaScript libraries relies on window innerWidth and innerHeight to do their calculations ...
3
votes
1answer
55 views

React.js Nested Nav Bar

This was written for a coding challenge for a company I recently starting working for. I'm looking for any suggestions on how to clean up the code, as well as any issues anyone thinks may occur as it ...
0
votes
0answers
34 views

Download NASA images to use as Windows wallpaper

I made myself a simple script (Batch/JScript) that download a pic from a blog (APOD) & set it as wallpaper. ...
0
votes
0answers
10 views

Using per-page SystemJS configurations (because of misbehaving dependencies)

Background I'm writing a server-side-rendering (i.e. "traditional") web-application that uses a dependency-free client-side components library (specifically, Syncfusion Essential JS 2). Ostensibly ...
3
votes
2answers
50 views

Listing the playlists on which each song appears

I created a way to export my Google Play playlists to a text file and also a way to export all of my songs in Google Play to a text file. Now I have both the song list (in an array format) and ...
1
vote
0answers
43 views

JavaScript Functions Vulnerabilities

I wrote the below code which contains the following functions: establish session with the user, determine if the user is authenticated, perform ping request, search about the user from the database, ...