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.

Filter by
Sorted by
Tagged with
1
vote
1answer
114 views

Given time intervals, find the minimum number of conference rooms required

The task is taken from LeetCode Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required....
20
votes
3answers
1k views

Terrain Generator - KhanAcademy

I'm new to JavaScript, and I've been learning off Khanacademy. I wrote the following basic terrain generator and I'm wondering if it could use any improvements. Here's the code: ...
20
votes
7answers
3k views

Find the longest word's length

The challenge is simple: Return the length of the longest word in the provided sentence. The solution is just as simple: ...
14
votes
5answers
7k views

Finding longest word in a string

I was working on a problem from Coderbyte. The challenge was to write a function that takes in a string and returns the longest word in the string. If two words are the same size then it asks to ...
14
votes
3answers
260 views

Mission impossible: beat everyone else to the queue

Your mission, should you chose to accept it, is to beat everyone else to the review tab so you get a chance to help out. This is a problem I've been running into lately. I go over to review tab, find ...
13
votes
1answer
267 views

A vanilla JavaScript library for typesetting pseudocode in HTML documents

I have this plain JavaScript library for typesetting pseudocode in HTML documents. (See the documentation for details.) (See the GitHub repository - broken as of now.) Source code algotype.js <...
12
votes
2answers
725 views

Simon says HTML5

Here's a little game written in HTML5 using bleeding edge audio. Since I don't do much HTML5 or Javascript, I'm particularly interested in: Structure Is this a reasonable way to structure the ...
12
votes
1answer
412 views

2D Gravity Simulator-like game

This project is pretty much like a 2D gravity simulator. You click and it creates a circle that attracts other circles. The result of a collision is a bigger circle that is a sum of the masses. If you ...
11
votes
2answers
302 views

Prorated refund calculator

I wrote this little piece of script for my workplace (insurance, etc.) to help our admins, as a light and simple file I can just email to my colleagues. The purpose of it is to calculate a prorated ...
11
votes
4answers
2k views

Gallery of employees with dynamic filtering

I'm trying to learn how to write better, more efficient JavaScript code and wanted to run this function I'd written by you and see if people can suggest an improved method. It's basically a people ...
10
votes
2answers
539 views

FizzBuzz in JavaScript using Ramda

Just getting up to speed in Ramda, I have implemented this: ...
10
votes
1answer
751 views

Card-fighting game

I am currently building my first game/app in javascript. It is a very simple script that has about 130~ lines of code. I feel like what I did so far is not optimized, can anyone please help me ...
9
votes
2answers
135 views

Script to convert Shift + Spacebar into four spaces on SE - Second Improvement

Secondary Review Changes: I recently requested a review: Script to convert Shift + Spacebar into four spaces on SE. After accepting suggestions and improvements by David Harkness, I heavily updated ...
8
votes
1answer
2k views

2048 (game) solver 2.0

Follow-up of 2048 (game) solver I improved the script, using standard search methods like expectimax. Now it goes easily to 2048, but not really further, the difference with the highly efficient ...
8
votes
1answer
268 views

Markdown to HTML, again

I made another markdown parser. (original, this one on github). Look, I'm not crazy (sorta), I just like making markdown parsers… ...
8
votes
1answer
232 views

Simple syntax highlighter in Javascript - SQL highlighting

Yesterday and today I've made a very basic syntax highlight. It creates a function in the window object that handles part of the job: ...
8
votes
4answers
1k views

Test if a string is a palindrome

I got this out of an article on interviews / code challenges. The challenge text goes like this: A palindrome is a word, phrase, number, or other sequence of characters which reads the same ...
7
votes
2answers
128 views

Interdependent color swatch widgets

To illustrate some algorithmic problems I found while writing this code review, I needed to include a live demonstration, which I implemented using a Stack Snippet with Angular.js. The demonstration ...
7
votes
3answers
519 views

Carousel in Vanilla JavaScript

I finally got my carousel to work in JavaScript, and I want to know what you guys think about it and what I can do better. ...
7
votes
2answers
944 views

Simplified Bin Packing using JavaScript

This code determines the maximum number of boxes (one size) that can fit into the back of a truck, checking all possible orientations to ensure maximum Bin Packing excitement. This is (hopefully) the ...
7
votes
1answer
176 views

Multiple inheritance pattern for vehicle information

I wanted an easy way to augment objects, by adding functionality from any other object(s). More importantly, I needed a way to augment the object from multiple sources in a clean one-line solution. ...
6
votes
1answer
80 views

Work order spatial query (Part 1)

Part 1: General Cleanup (Edit: Part 2 is here.) I have a script in a Work Order Management System (Maximo) that performs a spatial query. Details: Takes the X&Y coordinates of a work order in ...
6
votes
1answer
3k views

A simple MP3 player with React.js

I've been learning React.js for the last few days and am working on a simple MP3 player. I have a few years experience with JavaScript, however, I am just trying to get used to the idea of components ...
6
votes
3answers
5k views

JavaScript text-based RPG

I'm making a text-based RPG in JavaScript. It works but I'd like to know how to improve it, like code-wise. Also, I want to know how to make it run on anything other than Internet Explorer. ...
6
votes
1answer
615 views

JavaScript Breakout Game

I'm a novice programmer who is very new to JavaScript, and animation/graphics, and I have this breakout game on my flask website. I tried to do as much as I could from scratch, and I'm unsure if my ...
6
votes
1answer
5k views

Shopping Cart with React JS

I've just created my first set of related classes in React and would like to get feedback from more experienced React developers. I've used ES and completely vanilla React. The application is a ...
6
votes
1answer
572 views

Canvas animation

Just started learning how to use the canvas today as I wanted to copy an animated GIF. The GIF I tried to copy is below. The animation does work but I've hacked it left and right. There's obviously ...
5
votes
2answers
837 views

Simple math game in JavaScript

Created a simple math (addition/subtraction) game to practice my JavaScript. Any feedback on the JavaScript appreciated. Can play in: CodePen Instructions: A math equation will show up and simply ...
5
votes
2answers
295 views

Uploading multiple files to server with PHP and JavaScript

I wrote some code to upload multiple files to a server with PHP and JavaScript. I'm happy with the form and JavaScript, below. ...
5
votes
1answer
337 views

Two keyboard handlers for a video game character

The code below is equivalent. I can see pros and cons for both versions. Which is better: the short, clever way, or the long, ctrl+c way? Short version: ...
5
votes
1answer
295 views

Displaying JavaScript object's structure on page with HTML

I wanted to reproduce the type of navigation system found in the console of Firefox and Chrome: you can explore an object's properties by unfolding boxes: So I'm searching to: display all of the ...
5
votes
2answers
1k views

Handling multiple click events of sliding divs

You are first confronted by three links. Each link triggers divs to slide out. The divs slide out and up to appear as if unfolding. The slide back in reverse when any other link on the page is ...
5
votes
1answer
567 views

Traversing the parent-child relationship between objects

I wrote this code because I was often annoyed that I couldn't get the parent object. This class allows you to traverse the parent-child relationship between objects, in both directions. It also ...
5
votes
3answers
240 views

Simple Number to Words using a Single Loop String Triplets in JavaScript

I have extensively reviewed 2 old articles on the subject: https://stackoverflow.com/questions/14766951/convert-digits-into-words-with-javascript and https://stackoverflow.com/questions/5529934/...
5
votes
2answers
475 views

99 Bottles of Beer using polymorphism

This was part of an exercise from exercism.io. If you fancy, view the repo here. Given problem statement: Write a program which produces the lyrics to that beloved classic, that field-trip ...
5
votes
1answer
217 views

Rock-Paper-Scissors with the revealing module pattern

In my ongoing effort in learning advanced JavaScript I tried to develop the traditional rock paper scissors game by using the famous revealing module pattern. I'm not comfortable yet with what has to ...
5
votes
1answer
1k views

JS Progress Bar Widget

Demo of the widget: http://jsfiddle.net/slicedtoad/Lywvbsf4/ It's a progress bar that shows a list of steps and which one is being completed as well as allowing previous steps to be revisited. It ...
4
votes
1answer
428 views

Personal project for managing my bookmarks

I am working on a personal project for managing my bookmarks, which is basically a web page to manage my bookmarks by categories. Managing here means everything - adding, viewing, updating, searching ...
4
votes
1answer
2k views

JavaScript replace

I am not sure the square brackets are correct (although it has not yet failed some simple tests). I would also like to reduce and simplify this code to one line if practical. I think the code is self ...
4
votes
2answers
7k views

Simplifying an AngularJs directive that counts the number of characters entered in a textarea

I am trying to implement an AngularJS directive that would count the number of characters entered into a textarea and display it to the user. Note: it will actually become much more complex later on ...
4
votes
1answer
759 views

Getting a compass point from 140°

This JavaScript converts degrees to a compass point, e.g. convert.toCompass(140) gets 140° -> SE. I can't help but think: is ...
4
votes
2answers
3k views

Improving on John Resig's Simple JavaScript Inheritance: avoiding `new`

I've recently read this article, and I agree that the new keyword is not good practice. Thus, I've made an improvement on John Resig's Simple JavaScript ...
4
votes
1answer
277 views

Quadratic Equation Solver v2.0 in Javascript using Functional Programming

I have posted this in continuation to my earlier post Quadratic equation solver in JavaScript. Tried to improve on the shortcomings last time and also changed the logic. It is still not covering all ...
4
votes
3answers
89 views

Toggling only a single class as active in a list with vanilla JS or CSS

Every time I toggle active class in a list (to dynamically change DOM content) I find that I always go to this approach to check and clear which class is active. I'...
4
votes
1answer
239 views

Plotting discontinous function

I've made a simple web plot with D3 JS version 4. I've drawn a discontinuous function: $$f(x)=\frac{1}{x(x-2)}$$ which has 2 vertical asymptotes and 1 horizontal asymptote. I add a legend with LateX:...
3
votes
0answers
51 views

Fast algorithms in Javascript for shortest path queries in directed unweighted graphs

(There is a follow-up question available to this: Follow-Up Question) So I have this: ...
3
votes
1answer
3k views

Checking if variable is defined before accessing its properties [closed]

I didn't write this but I noticed it in our codebase at work. ...
3
votes
1answer
200 views

Tip Calculator in pure JS

A simple tip calculator that asks for the total bill amount, service quality (used to determine what percentage of the total cost will be tipped), and how many people are sharing the bill (used to ...
3
votes
1answer
420 views

Wrote javascript version of error monad / monadplus, did I obey monad laws correctly?

Just looking for some critiques hopefully from haskellers of how I might be breaking monad laws or just monadding all wrong. My or is something like the ...
3
votes
1answer
75 views

Can phrase be made from whole words in another string?

I am working to solve this HackerRank puzzle: Hash Tables: Ransom Note The premise is that if I am given a string like this: give one grand today I can find a match for each of the words in the ...