ECMAScript (commonly referred to as JavaScript) is primarily used for scripting web-pages but also has several embedded forms and stand-alone interpreters / JIT engines. Use this tag for questions regarding ECMAScript 5 or 6 and its dialects / implementations: JavaScript, JScript, etc., excluding ...
3
votes
0answers
9 views
My 15 puzzle solver is too slow
It takes my code over 700 seconds to solve simple puzzle:
2 13 14 10
7 0 1 3
11 9 8 12
5 4 6 15
My function findSolution(puzzle, minH) takes puzzle as ...
4
votes
1answer
33 views
Github pagination
I wanted to copy the behavior of github's pagination. Here is what it turned out: http://jsbin.com/dihohiseca/5/edit?js,output
It works fine, but I have a feeling that there is a lot of room for ...
2
votes
1answer
18 views
Combat simulator - single page JavaScript with requirejs from a Java Applet
Single-page web app from Applet
I'm seeking feedback on my first single-page web app using requirejs and a web worker. I converted it from a Java applet, and the code is up on GitHub.
It's a combat ...
3
votes
1answer
29 views
De Casteljau's Algorithm Tool for Khan Academy Contest
So I wrote this code for a contest going on over at Khan Academy known as "Pixar in a Program". The goal of the contest is to create an entry that uses one of the skills shown in the new "Pixar in a ...
1
vote
1answer
26 views
Javascript event handling via switch
The application I am developing with has many input fields that interact with one another via the onchange event.
When developing started, the goal was to create a framework that makes it easy to ...
5
votes
1answer
66 views
6
votes
2answers
27 views
Exposing a directive's computed variable
I have a directive called meetingList with its own isolated scope that receives a list of meetings and displays the filtered items based on some criteria. The ...
1
vote
0answers
10 views
Is setTimeout safe for scheduling jobs over large spans of time? [migrated]
I'm writing an application in Node.js that needs to schedule functions to be run at times hours or sometimes days in the future. Currently, I'm doing so with something similar to this:
...
2
votes
2answers
74 views
Solving for equilibrium index in an array
I did a sample on Codility and finished the test task.
The problem description is very short:
The equilibrium index of a sequence is an index such that the sum of elements at lower indexes is ...
1
vote
2answers
43 views
Copying a large number of DOM elements
The aim is to duplicate and append each .grid__item into the .gallery element. The following code was my first instinct, and ...
3
votes
2answers
40 views
Auto-complete in JavaScript
I recently got interviewed in a company for Senior level position. They asked me to develop auto-complete component (2 hours time limit) using plain JavaScript similar to this.
I wrote below code, ...
-1
votes
3answers
70 views
1
vote
2answers
38 views
Finding the differences between two revisions (or objects)
This detects the difference between two objects (or revisions):
...
4
votes
3answers
434 views
Generating random hex color in javascript
As the title says the function is for creating random hex colors.
Is there any better way to generate random hex colors?
...
2
votes
0answers
62 views
Getting rid of HTML file inputs once and far all
They've always annoyed me, and as a matter of principle, would like to leave my HTML/CSS intact and have the various file upload plugins work with consistent behavior with any styled element.
The ...
1
vote
2answers
29 views
Toggle based on checkbox
Can I improve this code ? it's pretty simple and self explain.
I have a table which has tasks with several statuses, user can use filter check-boxes to show and hide rows based on these status ...
0
votes
0answers
22 views
Creating API routes [on hold]
I have this piece of code, which is responsible for creating my API routes:
...
3
votes
1answer
31 views
Script that checks if an element is in or out of view
I'm looking for some performance suggestions. The purpose is to toggle a data attribute value indicating when an element is either in view or out of view. You can also assign callbacks to be called ...
0
votes
1answer
21 views
Generate table of contents form HTML
I've written a small bit of JavaScript which parses some HTML and generate a table of contents based on the various heading tags. The table of contents needs to be nested (E.g. ...
0
votes
0answers
13 views
jQuery Shooter Game Collision Doesn't Work [on hold]
I'm creating a jQuery web game for my Web Programming Class, and I've made it this far but I can't get collision detection to work, or particles to fire past top and bottom 90 degrees.
Also I'm a ...
6
votes
4answers
196 views
Add one to a very large integer
I was asked to implement this in an interview a while back. I didn't pass the interview, mostly likely because it took me far too long to do. However, I'm interested to know how well implemented the ...
-2
votes
0answers
22 views
Customised Highchart with SVG pattern
The script injects an SVG pattern into high charts, which seems better for responsive devices and visual accessibility. The code works but any advice on improvement/best practice would be welcome. ...
7
votes
1answer
46 views
Google Sheet with a column of names merged with Google Doc
I wrote my first script for google apps, but I am just learning how this all works. The script works fine, but I am sure there are things that are not done properly. Any advice is appreciated.
The ...
0
votes
1answer
44 views
Clicking outside a form
On click on a div, a form replace this div. When the user clicks outside the form, the form is hidden and the div is re-show. For this, I implemented this process and I want your feedback, please.
...
3
votes
2answers
63 views
Refactor if (else if) (else if) (…) else javascript
I'm kinda new to javascript and have question about it. Now my practical project is growing a bit bigger. I got the following if else statement. Is it possible to refactor this ? Should i use an use ...
2
votes
1answer
31 views
node.js CPU issue
Me and my friend are making a node.js game, and we have been testing cpu, but after profiling this process called zlib is sucking most of the CPU/RAM
3 clients connected to a game is fine, but when ...
0
votes
0answers
131 views
A dirty port of a Google Image Search layout clone jQuery plugin to Angular JS
I took the basic layout manipulation from a jQuery plugin called flexImages. The idea is to use the directive tag and encapsulate a piece of code that will be transcluded to make up the container ...
-2
votes
0answers
9 views
JavaScript Chunk System [closed]
I need to find a more efficientway of rendering items in a chunk and unload chunks i don't need, write now im getting the chunk that the player is in and setting it to a array (so if the player is in ...
1
vote
0answers
18 views
Return React child component based on current state
I am trying to build a multi page form widget with React for a website inspired by this. Since quite some time has passed since I last touched JavaScript, I'm directly adapting to ES6/7 and tried to ...
5
votes
1answer
34 views
Github Issue Viewer
I have the following javascript code that creates a github issue viewer. Can anyone give me some advice on how to improve the code?
...
0
votes
1answer
14 views
3
votes
1answer
37 views
Javascript: timer function
This is a function I made for a timer that counts down and performs a callback at the end. It seems to work fine, but I think the code is not very clean and has some unnecessary bits; also I would ...
2
votes
0answers
55 views
JavaScript library for material design toasts (notifications)
This question is a follow-up question to this one.
I wrote a small JavaScript library for material design toasts (notifications). I'd like to know what are my mistakes and how can I correct them? ...
4
votes
1answer
36 views
Horizontal accordian using jQuery
Hi I am trying to create a Horizontal Accordion using jQuery, the code works fine. I just want to know if my approach is correct and are there any improvements I could make to the existing code ...
2
votes
2answers
22 views
Comparing multiple variables and assigning new values respectively
I know there is a more elegant way to write this. The logic is solid and doing what I want it to, but I feel like when written like this, it is awfully cumbersome to have these many ...
0
votes
1answer
23 views
-1
votes
3answers
35 views
Sorting variables for human weight/length calculations
I'm trying to simplify this function, as there can be multiple type of data objects and for each type there is also a male and a female version.
The number and name ...
1
vote
0answers
70 views
Overlay on an image
This is, for instance, used on this page, and it overlays the main product picture with some DIVs:
...
2
votes
1answer
73 views
MySQL data fetching without page refresh
I've recently finished a prototype for a little Raspberry Pi website. The main page of the site displays current users found in the room (through bluetooth). I wanted this list updated regularly from ...
3
votes
4answers
314 views
Estimate code quality of my js library
I wrote a small javascript library for material design toasts (notifications).
Here's the github repo.
I'd like to know what are my mistakes and how can I correct them? Code works correctly and was ...
1
vote
2answers
46 views
Number to german decimal format converter function [closed]
I have a function that formats a number (even a float) to a German decimal format. I got this function from here ...
1
vote
2answers
25 views
Assign object keys to another object's keys dynamically
I have an array called viewObject.terms. This array can contain up to 3 items, I need to iterate through this array and save the values into a data object.
ie:
...
4
votes
1answer
40 views
Angular wrapper for SignalR event aggregator
I created a little wrapper for one of my JavaScript libraries to enable Angular functionality. Are there any pitfalls I should be wary of with my code?
...
0
votes
2answers
41 views
Genetic Drift Simulator - Follow Up
This question is a follow-up of a previous question of mine: Genetic Drift Simulator.
Following the advice given in the last question, and some more general improvements, the code has been slimmed ...
2
votes
1answer
34 views
Finding clients in a 100 km circle
I needed a node app that:
reads a list in text file format from URL
parses the rows on the list. (fields: id, name, longitude, latitude)
finds names of the people who live maximum 100 kms away from ...
9
votes
1answer
57 views
The Handy-Dandy Apocalypse Assistant
Code Review is running rampant with an infection. A zombie infection.
Everywhere posts are becoming rapidly mutated into slobbering, green
freaks of nature. But the citizens of Code Review are ...
0
votes
2answers
39 views
Concatenating multiple strings from a JSON response
I would like to concatenate a series of strings populated from an XHR response. So, I've chosen to do it like this:
...
3
votes
2answers
66 views
Slick Slider – change contents based on current slide data-index
I wrote the following code for Slick Slider, which changes the content below based on the current slide data-index. I just wonder if there is a more efficient way to do it?
...
1
vote
1answer
51 views
Node.js drawing game based off of my state diagram
I really want to have a nice design pattern for my Node.js project. This is my state diagram. As I'm coding this, I'm wondering if it's better to separate state logic from the class? So instead I ...
2
votes
0answers
39 views
leftMerge function to deep overlay saved state
This code is used to deep overlay saved state (as an object) over a template object, which is the current model, this model can change (e.g have new attributes added), and a simple _.clone call will ...