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
24
votes
1answer
37k views

Handling Hover Events on a Touch Screen

A website I have designed uses a nav menu that shows submenus on :hover. The initial site did not use any responsive design: it targeted only the desktop ...
24
votes
3answers
139k views

Removing duplicates from an array quickly

...
17
votes
5answers
133k views

Sorting an HTML table with JavaScript

The following code sorts an HTML table with JavaScript (without using any external libraries like jQuery). Are there any shortcomings or possible improvements I could make? ...
16
votes
2answers
14k views

Faster JavaScript fuzzy string matching function?

I'm using the following function to fuzzy match strings: ...
16
votes
1answer
38k views

Alternative to setInterval and setTimeout

JavaScript's setTimeout() and setInterval() are evil and not precise: Both functions have a delay of a varying quantity of ...
16
votes
1answer
4k views

Should I put default values of attributes on the prototype to save space?

Suppose I've got a JavaScript function that I'm treating like a class - that is, I want to make many instances of it: ...
12
votes
1answer
6k views

Simple trie implementation in JavaScript

After experimenting with a sorted trie implementation in C, I felt that I understood tries pretty well, but was having trouble explaining how they work. Since the C code was based on existing code, I ...
18
votes
6answers
34k views

Generate all possible combinations of letters in a word

This is a JavaScript function that returns ALL the possible combinations of whatever word the user enters. I am looking to clean this code up a bit...any and all suggestions are welcome! ...
26
votes
3answers
12k views

Usage of the ternary “?:” operator with functions listening to click events

I've recently been doing some mods to some old code I've been maintaining for a couple of years now. As part of a wider set of scripts using YAHOO YUI 2.2 (yes, that old) for dialog-style panels, I ...
22
votes
7answers
9k views

FizzBuzz in Javascript

I'm sure everyone here knows what FizzBuzz is. I would like constructive criticism for my solution. I'm a beginner to programming as a whole and this isn't my first solution, but it's what I think is ...
19
votes
2answers
45k views

Tic Tac Toe in plain JavaScript

I have created Tic Tac Toe game using plain JavaScript. Can any javascript expert review it and let me know whether the way I have written JavaScript code that is right (preferable)? I am unsure that ...
13
votes
1answer
13k views

Java JSON parsing with the Nashorn API

Some time ago I found a website about the Java Nashorn API which allows you to run JavaScript from Java code. I thought about creating a JSON parser in pure Java (without external libraries) which ...
40
votes
8answers
17k views

Rendering a person's time clock record in HTML, with many color-coded conditions

I have coded this mess of JavaScript and a bit of jQuery. Everything here works perfect as intended, however it is a real mess. What would be the best way to clean this up with best practices and ...
23
votes
6answers
4k views

Rock, Paper, Scissors, Lizard and Spock

I am currently done with this little Rock, Paper, Scissors, Lizard, Spock game in JavaScript. The game is working fine, but I am not pleased with the code. Is there a way to refactor these ...
10
votes
1answer
2k views

JavaScript “snow” animation

I have worked for a few hours and this is the result: ...
9
votes
4answers
2k views

A faster way to compute the largest prime factor

I am self-learning js and came across this problem(#3) from the Euler Project The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? ...
6
votes
2answers
414 views

Cake-ordering form and calculator

I’m a designer learning to code and I’ve built a simple form calculator for ordering cakes. I would love it if you could show me how to make the code more idiomatic. How can it be more consistent, ...
4
votes
2answers
707 views

iPhone notes application replica using HTML/CSS

I've written a web application that is a replica of the iPhone's notes app. It turned out quite well, you can do everything you can on the iPhone's app except for sharing and sending it via texts etc. ...
25
votes
9answers
41k views

Set of jQuery .onclick functions

I am hiding and fading in different content on the same page using jQuery to hide() and fadeIn() the content depending on which ...
13
votes
2answers
167 views

Bookmarklet for selecting code snippets on Code Review

The following code will add to each code block a 'Select Code' button that will select the code belonging to that block. Please review for maintainability. In order to use this, visit http://...
10
votes
2answers
781 views

Block building game

I've spent the last weekend working on this basic block building game, which I'm quite proud of. I do think it can be improved in many places though, e.g, performance issues due to my badly designed ...
9
votes
1answer
7k views

Implement numbering scheme like A,B,C… AA,AB,… AAA…, similar to converting a number to radix26

I want to implement numbering scheme like Microsoft Word uses for numbering. first one gets = A,next is B, next is C, .... then AA, then AB,....and so on. as shown below ...
5
votes
2answers
3k views

Safe navigating function for nested object properties

I've made a function to safely traverse deep objects. ...
5
votes
1answer
415 views

node.js Passport Wrapper 3

First attempt was done here Second attempt was done here Huge comment at top ...
4
votes
1answer
8k views

Wrapper for jquery ajax to ensure redirects occur on clientside

Recently I had the need to make some ajax calls within a MVC 3.0 with Razor and jQuery application. After a bit of trial and error and refactoring it was discovered that a number of different needs ...
3
votes
2answers
453 views

Splice from Array if index matches

This code loops through an array called $rootScope.watchlist (uses AngularJS). It gets the current iteration of the loop to access that x iteration through ...
1
vote
1answer
66 views

Setting Property Values Programmatically in a JSON Object

Through the lens of the SOLID principles, which one of the following makes the most sense? I want to ensure the approach I select keeps everything simple and maintainable as we add properties, modify ...
38
votes
5answers
7k views

JavaScript binary search

I wrote an implementation of binary search in JavaScript earlier for kicks, but I noticed my version was significantly different than those found on Google. Here is an example of binary search I found ...
26
votes
4answers
3k views

Self-playing Baseball game

The Demo for what I have made is located here Basically I am trying to make a self playing JavaScript baseball game with the use of no libraries. Is there anything I could improve on in the code? <...
18
votes
4answers
325 views

“The 2nd Monitor” chatroom translator

For those who go to The 2nd Monitor chatroom, you already know how bad I am at remembering everything. And, sometimes, the new visitors will wonder what something means. For that, I've developed a ...
15
votes
2answers
3k views

2048 (game) solver

The code contains an AI function, that searches breadth-first all possible moves and get the score of their grids, a depth of 6 is used which makes at most \$4+4^2+...+4^6\$ computed grids. The ...
15
votes
3answers
199 views

GitHub link oneboxer for chat

I've made a userscript that oneboxes links to GitHub repos, issues or pull requests in Chat after seeing the request One-box repositories, issue tickets and such on GitHub in the chat on Meta. It ...
13
votes
3answers
20k views

Escape user input for use in JS regex

I am building a highlight feature for search results on my website and need to escape the user's input so that I could highlight the matching string within the original text. The function ...
12
votes
7answers
28k views

Given an array of integers, return all pairs that add up to 100

I was recently given this programming challenge on an interview, and I decided to use javascript to solve it. I did, but I'm not happy with my implementation. I can't help thinking there must be a ...
11
votes
1answer
805 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 ...
10
votes
2answers
2k views

Tool for automatically correcting indentation and formatting of CR & SO code

This is my tentative solution to: How can I prepare my code so that I can paste it formatted? If you need to copy and paste code into the question or answer textarea when solving someone's problem, ...
10
votes
2answers
264 views

“Stardust” 2D Gravity Simulator - Follow Up 1: The Planets

This is a follow up for the 2D Gravity Simulator-like Game question. Since then I have developed my javascript skills further, and now I'm using ES6 mainly. Note that even through this code uses the ...
9
votes
3answers
628 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. ...
8
votes
2answers
321 views

Usability of API to declare modules in JavaScript

Edit: I updated the JavaScript modules in http://enlargeyourpassword.com to use scope(). You can see the result in the source of the page, and get an idea of the process by looking at the commit ...
8
votes
1answer
575 views

Creating Inheritance hierarchy using function constructor

Problem statement You need to create the Animal base class having four fields: a. name b. ...
7
votes
1answer
16k views

Checking for balanced brackets in JavaScript

I'm wrote a simple function isBalanced which takes some code and returns true if the brackets in the code are balanced and ...
7
votes
5answers
482 views

Conway's Game of Life and Other Lifelike Cellular Automata Rules

This simulator visualizes Conway's Game of Life and other lifelike cellular automata rule-sets. Features: You can choose from any of the preselected birth/survival thresholds or specify custom ...
6
votes
1answer
2k views

Improvements to an Angular ScrollSpy module

Things that I'm not sure about: Whether this works in all use cases - alongside routing and within templates etc Am I polluting the scope with all these variables? This seems to be the easiest way to ...
6
votes
1answer
2k views

Plugin that conditionally displays elements based on form values

I've just released a jQuery plugin that conditionally displays elements based on form values. I would appreciate any suggestions on how to improve both the code and its usefulness. Here's the demo ...
5
votes
2answers
396 views

Random tone generator using Web Audio API

This is a random frequency audio generator made with the Web Audio API by Mozilla. The end-goal is an audio frequency trainer: the website plays an audio frequency and the user tries to guess which ...
4
votes
1answer
272 views

Simple JavaScript (sub) class [properties, getters, methods]

The more I consider object oriented JavaScript the more I am confused. There are so many different ways and concepts and I simply do not know any longer what fits best for my purposes. I like the ...
4
votes
1answer
493 views

Javascript Queue Object

I created a Queue object when answering this question and I was wondering if it could do with some improvement. Here is the current code: ...
4
votes
2answers
109 views

AJAX communication with pure JS and PHP

I'm looking for a good approach to AJAX communication using only pure JS and PHP. I would like it to be as safe as possible and compatible with most modern browsers and IE 10+. I did some research and ...
3
votes
1answer
199 views

Splitting canvas app into separate functions

This is all in one methods but I would like to see it in individual separate methods. The code works fine but all of the code is in the canvasApp() methods and I ...
3
votes
2answers
1k views

Implementing RadixSort using JavaScript

Can someone review my code? I am trying to implement radix sort in JavaScript. ...

1
2
3 4 5
8