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
109
votes
4answers
20k views

Celebratory fireworks animation

To celebrate an important event, I hastily cobbled together an HTML canvas-based animation. A few concerns I have include: Performance: Does it run reasonably smoothly on most modern machines? How ...
77
votes
6answers
7k views

You hate h̶a̶t̶s̶ reputation? Click here to get rid of it

Soo... I recently read a meta-post about the inherent problems of reputation. It listed some things like: Confirmation bias. Demotivating for low-rep users. Hubris and elitism of high-rep users over ...
75
votes
7answers
148k views

Convert object array to hash map using lodash

The use case is to convert an array of objects into a hash map where one property is the key and the other property is the value. Common case of using this is converting a "link" object in a ...
67
votes
9answers
101k views

Generating all combinations of an array

I'm generating all combinations of an array, so for instance, ["a", "b", "c", "d"] will generate: ...
54
votes
4answers
176k views

Grouping elements in array by multiple properties

During work, I was given this task: to group elements with similar properties in the array. In general, the problem is as follows: ...
51
votes
5answers
35k views

Verifying password strength using JavaScript

I have a function which verifies the "Password" field and suggests the user to enter a strong password. I also have a label named "Password Strength", referring to the strength of a password (very ...
49
votes
6answers
44k views

Using var self = this or .bind(this)? [closed]

I was curious which way is generally preferred, or if there is even a preference, given these two options: ...
46
votes
7answers
3k views

Who's in the fellowship? When are Frodo, and the rest of the gang, together

As a variant on the fizzbuzz concept, and as an exercise for learning JavaScript, HTML5, and CSS (I know none of them very well). The regular fizzbuzz is somewhat tired, but having a web-based, ...
44
votes
4answers
8k views

Conway's Game of Life in JavaScript

I made Conway's Game of Life in JavaScript and was hoping someone could give me some pointers regarding my logic of checking adjacent cells. I know there must be a better way, but at the same time, it ...
41
votes
10answers
62k views

Given an array of integers, return the smallest positive integer not in it

Write a function: function solution(A); that, given an array A of N integers, returns ...
40
votes
5answers
22k views

Determining if two words are anagrams

I was given a this problem at a technical interview and failed miserably in the time given. Afterwards, I sat down and worked out what I think is a good solution. The task was actually to build an ...
38
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 ...
38
votes
2answers
34k views

Balanced parentheses

Given an expression string exp, write a program to examine whether the pairs and the orders of "{","}","(",")","[","]" are correct in exp. For example,...
38
votes
1answer
448 views

Beta-Blue B. Gone

I've written a Code Review design using Userscripts and CSS. It works by fetching the CSS from my GitHub repo, and using the built in gm_addStyle function to add ...
36
votes
5answers
142k views

String.IsNullOrEmpty in JavaScript

I am aware of it being frowned upon to do something like write C# in JavaScript. (see this if you don't know what I'm talking about) But as a judgement call, I think we could stand to have a ...
36
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 ...
35
votes
2answers
2k views

Random clothes generator

For the past four years I've attended a private school which requires its students to wear ties. I've found that it's far easier to figure out what combination of shirt, pants, and tie that go ...
33
votes
4answers
1k views

Memory with a twist

Description This is the good old game Memory with a twist: Every time you pick a wrong pair, the two tiles you chose will switch their location. So sometimes you might think that a tile is at one ...
31
votes
4answers
3k views

When “How To Ask” is too subtle

This is the first JavaScript code I've ever written, alert("hello, world!"); aside. This site is closing quite a lot of questions because people won't read the ...
30
votes
6answers
3k views

To 'this' or not to 'this'?

I was given a homework and I have 2 solutions: one that uses this and other one that doesn't. I tested both solutions on jsPerf but sometimes it says the version ...
30
votes
3answers
2k views

Regex to parse horizontal rules in Markdown

I'm the current maintainer of Showdownjs, a markdown parser off which PageDown (stackexchange's markdown parser) is based on. Showdown uses the following regex to parse horizontal rules: ...
29
votes
4answers
3k views

Snowfall in HTML

I am a beginner and I have made Snowfall in HTML for my mom. I'm pretty sure it will not look that awesome to any developer out there, but hey, that's why I've posted it. I'd like a general review of ...
28
votes
3answers
1k views

Code indentation for declaring inputs/outputs in an array

I'm writing a list of inputs and outputs for to be compared in unit tests. ...
28
votes
1answer
64k views

Pack and unpack bytes to strings

I need to write a function that "packs" an array of bytes (integers between 0 and 255) into a string. I also need to be able to perform the reverse operation, to get my byte array from the string that ...
28
votes
2answers
57k views

Recursion vs iteration of tree structure

Some recursive code is part of a particularly slow path of a project. Out of curiosity I was playing around with reimplementing the code using stack context iteration instead of recursion. Below are ...
27
votes
1answer
917 views

Javascript Minesweeper (with Stack Snippets!)

As Stack Snippets are live on Code Review now, I wanted to do something quick in it as part of rolfl's challenge on meta. And when you make things quick, they probably get dirty. And when things get ...
27
votes
1answer
388 views

Managing network address information

I'm a developer at a networking company that really has no peers that work above me that I can use for any sort of sounding board for my code, so it's just me. I was wondering if anyone would be ...
26
votes
3answers
11k 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 ...
26
votes
2answers
657 views

Desktop Notifications for flags and queue items

After our recent election, I got elected as a moderator here on Code Review (Thank you, community members!). One of the first things I missed among the moderator tools was desktop notifications for ...
25
votes
3answers
2k views

WebTorrent player

I have been working with HTML5 and CSS3 for a long time now, but have avoided JavaScript because of my belief that it's most frequently used unnecessarily while having a tendency to be poorly written. ...
25
votes
2answers
31k views

Capitalize the first character of all words (even when following a '-')

I got it working, all variations are displayed Sint-Anna as should be, but I wonder, is there a simpler way to this, since it looks very cluttered? ...
25
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? <...
25
votes
3answers
10k views

Sandbox or safely execute eval

In a large project of mine, I've run into a situation where a client might need to run evaluated JavaScript code. I know, it makes me cringe too. One option is to manually parse it, but for future ...
24
votes
9answers
35k 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 ...
24
votes
5answers
766 views

Templating libraries' intelligibility and their performance (compared to mine)

I've just started writing my own little templating library in JavaScript, because as I went through others, there is always this voice in head, which says: "Oh, this is a lot of code and functionality....
24
votes
3answers
135k views

Removing duplicates from an array quickly

...
24
votes
3answers
2k views

Simple object-oriented calculator

After studying several ways of doing OOP in JavaScript I think I finally came up with one that seems OK to me. Is it okay? Do you see some problems I can face by using OOP in JavaScript like this? ...
23
votes
7answers
6k views

Trapping Rain Water

This task is taken from Leetcode - Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. ...
23
votes
3answers
6k views

Converting an IP

I've written a DNS tool in Node and would like to know if there's a better and more efficient way of handling the conversion from an IP to a long. I'm not too good at bitwise just yet and would like ...
23
votes
1answer
35k 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 ...
22
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 ...
22
votes
2answers
556 views

Code-Q2A - copy code blocks from questions to answers

I came up with an idea for a userscript to simplify writing answers on Stack Exchange while writing a previous answer. This userscript adds "Review"-links on the top of each code segment. When ...
22
votes
1answer
1k views

Dynamically generating a list of events

This is a simple list of items in a list, which allows the user to dynamically generate that list of events. Then a controller action does the work of serializing that into the database. The issue is ...
22
votes
1answer
1k views

Brainfuck interpreter in JavaScript

Just what it says on the tin: a brainfuck interpreter in JavaScript. ...
21
votes
6answers
6k views

To-do list in jQuery

I'm making a simple to-do list with jQuery. This is my first step in JavaScript and jQuery. How can I improve my code? User enter tasks in input field, submit by pressing 'Enter'. On double-click, he ...
21
votes
3answers
2k views

HTML Editor: online HTML editor with real-time preview

HTML Editor is an online HTML editor with a minimalist approach. Edit your HTML, CSS, and JavaScript code and monitor the instant live preview. Please review the source code and provide feedback: <...
21
votes
1answer
15k views

Simple Async Google Maps initializer with AngularJS

Here is a simple reusable AngularJS factory I came up with to initialize Google Maps Asynchronously, which somehow does not seem ...
21
votes
1answer
5k views

Writing a better alternative to jQuery Autocomplete

Over the last months I have been writing a jQuery plugin called Better Autocomplete (Code on Github). It originated from another project, a Drupal module called Linkit, but I decided it should be a ...
20
votes
10answers
15k views

Sum of numbers separated with comma

I am very new to HTML and I've decided to attempt to put what I know into an HTML page that allows you to enter any amount of numbers, separated by commas, and would display the sum of all the numbers ...
20
votes
4answers
3k views

Count all vowels in string

For a homework assignemnt, I was asked to complete this CodeStepByStep problem. It's coded correctly and gave me a right answer. I'm just wondering if there's an easier way to solve this problem ...