Questions tagged [javascript]

JavaScript is primarily a language focused on web development. Being a monopoly on the front end and having Node on the back end. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too.

Filter by
Sorted by
Tagged with
2
votes
3answers
5k views

How to set multiple variables at once in JavaScript? [closed]

I have been setting multiple variables like this ...
2
votes
2answers
650 views

JavaScript queue implementation using linked list

Are there better ways of modularizing the code? Does it contain things JavaScript experts would avoid? Is it idiomatic? Is there a better way of signaling an empty queue than returning ...
2
votes
0answers
55 views

Performance of a jQuery module

Following this question, I've rewritten my module as follows: ...
2
votes
1answer
3k views

Approximating/Sorting groups of dates into buckets

I'm working on a directed study project with a professor of mine helping him build out a Django based website. The website is a historical account of the people, events, projects, and organization in ...
1
vote
1answer
1k 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....
21
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: ...
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: ...
14
votes
3answers
265 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 ...
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 ...
13
votes
1answer
315 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
1answer
437 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 ...
12
votes
2answers
310 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 ...
12
votes
2answers
755 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
2answers
362 views

Vue - It's the Royal Game of Ur

Background After learning Kotlin for Advent of Code in December, I started looking into cross-compiling Kotlin for both the JVM and to JavaScript. Then I wrote a game server in Kotlin and also a ...
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 ...
11
votes
2answers
581 views

FizzBuzz in JavaScript using Ramda

Just getting up to speed in Ramda, I have implemented this: ...
9
votes
2answers
138 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
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 ...
8
votes
1answer
275 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
238 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
1answer
3k 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 ...
7
votes
4answers
370 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/...
7
votes
2answers
1k 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
2answers
129 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
1answer
178 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
578 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 ...
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
138 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
4k 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
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
689 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 ...
5
votes
2answers
529 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
2answers
518 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
339 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
2answers
2k 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
1answer
718 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
1answer
240 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

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
2k 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
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
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
295 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:...
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
490 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
366 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
1answer
774 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
3answers
562 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
1k views

Circle - Line segment collision

I wrote an implementation of circle - line segment collision detection algorithm. Here is quick demonstration how it works: And here is my implementation in Javascript using HTML canvas: index.html ...
3
votes
2answers
181 views

Lightweight shorthand JS library

Long story short: I wanted some of the time-saving functionality of jQuery without the bulk of the entire library. So, I wrote a lightweight shorthand library inspired by jQuery I'm calling Mozart JS, ...

1 2
3
4 5
8