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.

2
votes
0answers
8 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 ...
2
votes
2answers
40 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: ...
0
votes
1answer
12 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 ...
0
votes
1answer
18 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 ...
-4
votes
0answers
23 views

My HTML code is not working in IE while it is working in chrome [on hold]

Since my code is confidential (Company) I have 2 dropdown boxes lets say 1st Dropdown contains A B ...
2
votes
2answers
29 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 ...
4
votes
3answers
45 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: ...
0
votes
0answers
14 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
27 views

Creating a better loop [on hold]

So I have created this loop: ...
-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
53 views

Creating a random number from 1-13 using a rand11 function that creates values from 1-11 [on hold]

I'm creating a function(i.e. rand13()) that creates a number from 1-13 using a function inside the rand13 function called ...
0
votes
0answers
14 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
16 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). ...
-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% ...
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 ...
3
votes
1answer
41 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
29 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
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 ...
-3
votes
0answers
22 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 ...
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
37 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, ...
1
vote
2answers
62 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 ...
-1
votes
0answers
14 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
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 ...
-4
votes
1answer
42 views

JavaScript Code - Your Opinion [closed]

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 ...
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: <...
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
42 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 ...
-3
votes
0answers
17 views

I want to display the details of each existing team with buttons [closed]

This component i already create by react-js . ...
0
votes
0answers
26 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 ...
-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
38 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. ...
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 ...
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 ...
4
votes
3answers
57 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: ...
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 ...
3
votes
1answer
78 views

Swap even and odd bits of unsigned 8-bit integer

The task: Given an unsigned 8-bit integer, swap its even and odd bits. The 1st and 2nd bit should be swapped, the 3rd and 4th bit should be swapped, and so on. For example, 10101010 should ...
1
vote
0answers
33 views

React hook “select all” checkbox implementation

This is a select-all checkbox (and checkboxes that it controls), that's usually found in tables/lists. Two things I'm concerned about: I'm returning elements from a React Hook - is that OK to do? As ...
0
votes
1answer
66 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
37 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
1answer
61 views

Find out whether string A can be shifted to get string B

The task: Given two strings A and B, return whether or not A can be shifted some number of times to get B. For example, if A is abcde and B is cdeab, return true. If A is abc and B is acb, ...
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 ...
2
votes
2answers
67 views

Reach to the last index starting at index 0

The task: Given an integer list where each number represents the number of hops you can make, determine whether you can reach to the last index starting at index 0. For example, ...
1
vote
0answers
18 views

jQuery plugin for allowing only digits to be entered in html form input

I wrote this small jQuery plugin to set some fields so that they allow only 0-9 digits to be entered. I intended to do that by preventing user from typing, pasting or dropping non-digit content. It ...
0
votes
1answer
45 views

Reduce a grid array [][] into a string

I have a class with a property of grid[][] and each value is either true or false. I need to convert this to a string with letters o and b in place of the boolean. ...