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.

0
votes
1answer
24 views

Async Await call gets made 3 times to return an array of prices based on asset

Function getMarkets Makes a call to get Cryptocurrency Exchange data based on asset (USD, USDC, USDT) It calls the endpoint 3 times to return 3 arrays which are then returned to the callee. I have ...
0
votes
1answer
80 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 ...
1
vote
0answers
23 views

Print out N by N Spiral Matrix in javascript

I got this question during on of 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: ...
3
votes
1answer
40 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 ...
8
votes
5answers
144k views

Get the value of the name attribute of each element with class=“class”

I need a function to get the value of the name attribute of each element with class="class". I was wondering what is the best way to do this, performance-wise. Currently I'm using jQuery and doing it ...
7
votes
3answers
8k views

JavaScript solution for diagonal difference

hackerrank.com - diagonal difference: Problem Statement You are given a square matrix of size N×N. Calculate the absolute difference of the sums across the two main diagonals. Input ...
0
votes
0answers
12 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
votes
0answers
26 views
-1
votes
0answers
20 views

Nesting functions while mapping a response with multiple layers [on hold]

I am wondering if this is the correct way to do it, because currently all functions are declared with every instance of the object they are used in. If I use classes with prototypes instead, the ...
-2
votes
0answers
51 views

Creating a random number from 1-13 using a rand11 function that creates values from 1-11

I'm creating a function(i.e. rand13()) that creates a number from 1-13 using a function inside the rand13 function called ...
1
vote
1answer
36 views

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

Some JavaScript libraries relies on window innerWidth and innerHeight to do their calculations ...
0
votes
0answers
13 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 ...
0
votes
0answers
12 views

React Context API and useContext hook

I'm looking for some feedback on an approach I'm testing out related to React.js Context API and the useContext Hook. My goal ...
-1
votes
0answers
13 views

Javascript refer to index like typescript enum, refactor

I have a const object that I refer to. I refer to both the key and the value. For reasons beyond me, I don't want to directly use the key (since it is an integer). ...
6
votes
4answers
11k views

Sorting dates in this format (DD-MM-YYYY)

Is this the correct and an elegant way to sort the dates in the format (DD-MM-YYYY) in ascending order? ...
-2
votes
0answers
20 views

How to handle race condition with animation in javascript [on hold]

I have a button on click of which I fadeOut an UI element, do processing to receive some data & then re render that UI element based on the received data. The problem here is, between animation &...
4
votes
1answer
41 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
26 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% ...
2
votes
2answers
37 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 ...
0
votes
0answers
32 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, ...
0
votes
2answers
59 views

Reverse the words in string

The task: Given a string of words delimited by spaces, reverse the words in string. For example, given "hello world here", return "here world hello" Follow-up: given a mutable string ...
0
votes
0answers
28 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. ...
3
votes
5answers
190 views

Selectable date filters

I created a simple app with Backbone and Marionette. In a view I created an onRender function. I created a page that displays a Report with a date filter, using a select tag and affect to an input ...
0
votes
0answers
7 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 ...
0
votes
0answers
10 views

show icon in input when user insert a value react js

I have an autocomplete input when user is not enter any value I want to hide the icon (x) when user insert a value if the input length >= 1 I want the icon appear in input I did something but can not ...
2
votes
1answer
54 views

Validating Array before rendering

I am rendering a list from an array of objects. I want to check the correctness of the array before rendering. For that I am using typeof and null. In real situation the list comes from the API. Is ...
4
votes
1answer
6k views

Regex for domain validation name validation

I created this regex in Javascript that returns a boolean for Domain validation that meets the criteria to allow IP addresses and ascii domain name. The assumption is that the TLD should be atleast ...
-3
votes
0answers
21 views

HTML5 Canvas JS - draw multiple images on one canvas from array of image data [on hold]

I'm struggling to store image data to an array, and then recall that data to be drawn on a canvas at a later time. My app has the ability to add new contexts, switch between them, and edit them ...
0
votes
0answers
10 views

Collapsible left-side tree

I was wondering if there is a better way to write the following code? The code is working, I am looking for better technique to achieve the functionality, if any exists. Never mind the classes that ...
-1
votes
0answers
13 views

Is xss exploits are possible with angular double braces [on hold]

I'm trying to secure my application and i would like to know if an XSS exploit is possible with this type of code ? Thanks ...
0
votes
2answers
52 views

JavaScript DOM Implementation

I'm supposed to create a website that adds multiple forms to the page, is responsive and checks if the inputs are valid (validation is not important, just needs to show some attempt at regex). Below ...
1
vote
1answer
145 views

Databinding entire objects between child Vue components and the root Vue instance

I have a form in which I am collecting data from two applicants. In order to minimize HTML duplication I built an applicant Vue component that generates each applicant from a template. Each ...
0
votes
0answers
35 views

Find all starting indices in a string which are anagrams of a word

The task: Given a word W and a string S, find all starting indices in S which are anagrams of W. For example, given that W is "ab", and S is "abxaba", return 0, 3, and 4. My solution: <...
-4
votes
1answer
37 views

JavaScript Code - Your Opinion [on hold]

I wrote the following javascript code and I need someone to review it and give me his opinion about my stracture, flow, mistakes (if exits) and things I have to avoid. The code contains the following ...
5
votes
6answers
2k views

Calculating Fibonacci numbers

The following problem is currently taking more than 8 seconds to execute. Please help me to modify the program, so that execution time will be reduced. ...
0
votes
1answer
36 views

Calling token API

I'm calling an API to request token, and making sure i'm not leaving any corners for errors and handle the result appropriately. It's a web service POST call in general, The code gets credentials, ...
1
vote
2answers
123 views

Simple menu with descriptions

If one menu-item is clicked then the description with the same data-filter attribute should be shown. I added a class to the description elements to associate each one with the affiliated menu item. ...
3
votes
1answer
41 views

A simplified Tetris solver

As part of an job interview process, I was tasked to write a solver for a simplified Tetris game using JavaScript. The game board size is 4x4 and there are 4 different pieces given in a .txt file. It ...
0
votes
0answers
9 views

Opening document link in new tab with other variable code [closed]

I have a document set to display some "Thank You Code" for 10 seconds, after which it displays a document attached to a Pardot download form. The Pardot form is iFrame, which means the document ...
3
votes
1answer
44 views

Passing a callback to a component in Vue.js

I'm currently trying to teach myself Vue.js and I've just created my first small project: a simple todo list. While writing the component I discovered that you can't access methods from the parent ...
0
votes
1answer
65 views

Return a sorted ordering of courses such that we can finish all courses

The task: We're given a hashmap associating each courseId key with a list of courseIds values, which represents that the prerequisites of courseId are courseIds. Return a sorted ordering of ...
0
votes
1answer
56 views

Adding <li> items dynamically to a to-do list

For a homework assignment, I have to create a "TO-DO" list, which will add a list item to the unordered list dynamically using JavaScript. The input element is also added using JavaScript, having to ...
-3
votes
0answers
17 views
0
votes
0answers
23 views

When slide show web page is reopen, the web page loading is very slow

Here is a script that opens about 200 pictures, the first time you open the webpage, loading of the 200 pictures is fast, However if you reopen the page, it takes about 4 minutes to load the same page ...
3
votes
2answers
1k views

Longest common prefix

I have made a function for finding the longest common prefix for the challenge on the leetcode site. This is the code: ...
4
votes
5answers
89 views

Get n-th perfect number

The task: A number is considered perfect if its digits sum up to exactly 10. Given a positive integer n, return the n-th perfect number. For example, given 1, you should return 19. Given ...
-2
votes
0answers
36 views

Looking for more professional way to rewrite the code any suggestion? [closed]

I am new in react js so I have done something but I knew that there are more clear and readable way to write the code. Can you please guys help me about this component. how to do state management. ...
3
votes
1answer
36 views

Hash table with complex variable-length keys

I'm trying to implement the game Snake in Javascript and getting the computer to play it by itself, and want to check whenever the snake loops (repeats the same set of moves twice) so I can kill it. ...
4
votes
3answers
56 views

Uniformly generate a number from 0 to n-1 that isn't on a blacklist

The task: Given an integer n and a list of integers l, write a function that randomly generates a number from 0 to n-1 that isn't in l (uniform). Solution 1: ...