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.

-4
votes
1answer
33 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 ...
0
votes
0answers
24 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 [on hold]

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
36 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 [on hold]

This component i already create by react-js . ...
0
votes
0answers
18 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
35 views

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

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
34 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
52 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
85 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
51 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: ...
1
vote
0answers
23 views

Filtering users in socket.io and seeing who is online

While implementing socket.io on my server, I ran into some problems and eventually fixed them. The code below is fired on the connection event of socket.io: ...
3
votes
1answer
41 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
75 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
17 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
58 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
30 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
54 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
40 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
66 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
17 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
43 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. ...
2
votes
3answers
59 views

Contiguous elements of the list sum to K

The task: Given a list of integers and a number K, return which contiguous elements of the list sum to K. For example, if the list is [1, 2, 3, 4, 5] and K is 9, then it should return [2, ...
1
vote
1answer
37 views

Slots and Dynamic Components

It's an exercise from a Vue.js course I'm enrolled into. The aim is to get comfortable with the Vue.js features Slots and Dynamic components. By clicking on the buttons one shall be able to change the ...
0
votes
0answers
19 views

UpvoteJS, a simple voting widget in vanilla JavaScript

I implemented a simple voting widget like the one used on Stack Exchange sites, to use for other purposes (see live on bashoneliners.com), as a reusable package, dubbed UpvoteJS. Here's how it works: ...
1
vote
0answers
16 views

Sparking animation for Button

I just came through a GitHub repo, which has an amazing animation for Button in Android. So, I though why not make that for web buttons too. And I started ...
2
votes
2answers
50 views

Return the shortest substring containing all the characters in the set

The task: Given a string and a set of characters, return the shortest substring containing all the characters in the set. For example, given the string "figehaeci" and the set of characters ...
-1
votes
0answers
15 views

Reftorar código [closed]

Qual melhor forma de refatorar esse código e deixar o mais curto possível em TypeScript sou novo nessa demanda. Ele Recebe um JSON e compara para achar uma imagem em um diretório onde nome da imagem ...
0
votes
2answers
35 views

The function to convert an object to a URL string

There is a function to convert object to the GET parameters for the ASP.Net controller. Is it possible to minimize the redundancy of the code, but not to the detriment of its readability? ...
0
votes
0answers
19 views

React application with redux and thunk to interact with REST endpoint [closed]

I am trying to learn the react and I have built and small TODO application which allows you to add and delete TODOS and it interacts with REST server. I am using Redux for handling state and thunk ...
2
votes
1answer
49 views

HTML form with confirmation before submission

I'm creating a website about an auto show that the user is going to. I'm collecting input from them via textboxes, check boxes, radio buttons, etc. I'm presenting them with a confirmation that the ...
2
votes
1answer
73 views

Crypto for a funny contest with friends

I am participating in a funny crypto contest with my friends. This time, we raised the bar quite a bit. The code below is my take for the constraints we set. Note that on my machine, the code works ...
2
votes
2answers
58 views

JavaScript flood fill

I tried to implement a very simple color flood fill to experiment a bit with Javascript. All comments about the code are welcome but I am especially interested in performance as it seems to be a bit ...
5
votes
2answers
71 views

Simple front end TODO list

I have implemented a very basic TODO List with no database or backend support. Though I have coded in C++ and Python before, this is my first HTML and JavaScript code. Please review the code and let ...
0
votes
0answers
38 views

Bucket sort algorithm in JavaScript

I was asked to implement bucket sort recently from my friend. Bucket sort is mainly useful when input is uniformly distributed over a range. For example, consider the following problem. Sort a ...
-2
votes
1answer
36 views

Simple conditional operator optimization [closed]

I have a repetitive set of instructions that I would like to optimize. Is there a better pattern to achieve the same goal but with less repetition ? ...
3
votes
1answer
35 views

Check whether a number can be dialed on a phone keypad without diagonal moves

I'm trying to write/come up with an algorithm for a phone keypad traversal. Let's say I have a rook on a keypad. The rook can traverse only horizontally and vertically. My code has to input a phone ...
2
votes
2answers
55 views

Mean by properties in array of objects

I have this array of objects: ...
2
votes
1answer
25 views

json2CSV fails because of lack of RAM memory

I run this code on my Heroku Node.js server in order to get CSV for few hundred rows, but it fails with R14 - Memory Quota Exceeded. It worked fine when there were ...
2
votes
1answer
39 views

splitting and merging Ranges array in javascript

I have an array of ranges as you can see in the snippet. when user select certain number from dropdown I want to remove that number from the range and return new ranges, Everything is working as per ...
2
votes
1answer
39 views

Symfony AJAX comment system with votes

How can I improve this code ? It was quite hard to implement AJAX comment system in Symfony 3, and result is a bit of mess: Controller: ...
0
votes
2answers
37 views

Filter non-duplicate objects from collection

I need to filter an array of form controls to check for duplicate values. I have written the following algorithm to identify and return an array of the controls which have are duplicates. I have not ...
0
votes
2answers
69 views

Find the length of the longest consecutive elements

The task: Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, given [100, 4, 200, 1, 3, 2], the longest consecutive element ...
0
votes
2answers
39 views

Fastest way to retrieve information from array and display in html

I am creating an app in html5 for mobile, and I have all the information of the items inside an array with 887 entries. Each entry have 32 key with values, some with more than one value. I am using a ...
0
votes
1answer
27 views

Creating Simple New Elements, Object Instances and Assigning IDs

I've created a simple demo that creates new elements on a page. After clicking the button, new elements are created, and when clicking remove, the relevant element is deleted. Each element has a 'data-...
0
votes
1answer
23 views

Optimizing NGRX reducer

I am trying to optimize my reducer code, preferably into one-liner with high-order-functions. Reducer should return new array with names of groups, with new number. Below are correct inputs and ...
0
votes
1answer
60 views

JavaScript Tic-Tac-Toe

The first function makes 2 players ...
0
votes
0answers
17 views

Efficiently updating relationship entities with Sequelize

I'm refactoring a method for saving Stuff entities that belong to some Person. This is the current code: ...
0
votes
1answer
35 views

Returning a new object reference when mutation happens

i attempted to create a way (not sure if already implemented by someone) by which when i update a property of an object. it returns a new reference of the object with the new value. i have a usecase ...