This challenge is related to the JavaScript language. Note that challenges that require the answers to be in a specific language are generally discouraged.
-4
votes
0answers
37 views
Exercism (javascript) palindrome-products requirements [on hold]
I'm working on the exercism.io javascript puzzle palindrome-products and I'm having a hard time understanding the requirements of the first test in the test-suite.
As I understand the first test for ...
-5
votes
0answers
71 views
Write the ugliest Javascript conceivable [on hold]
After being a C++ programmer who has never used js, being assigned js projects for 5 months, I have finally snapped and realized js can be made so ugly its an art.
var t2b= {id:0};
...
35
votes
2answers
467 views
JSF**k with only 5 symbols?
This is not a challenge but a question, I figured it was on topic because of
Non-challenge questions that are related to solving programming puzzles or a particular type of challenge are also on ...
11
votes
3answers
629 views
Generating the alphabet in JavaScript
I'm pretty sure there's not a better way to do this but figured it couldn't hurt to ask.
I'm tired of typing out a='abcdefghijklmnopqrstuvwxyz'.
Cool languages have Range('a'..'z') or similar
What ...
54
votes
18answers
2k views
King of the Hill - Spacewar!
If you've ever played Spacewar!, you know it was a fun game. If you haven't, know this: it was (and is) one of the very first and most important computer games. And it's still fun! The clone I grew ...
17
votes
5answers
978 views
Fibonacci in +!()[]script
Write a piece of JavaScript code that calls alert with an array containing the first 50 Fibonacci numbers in order. You may only use the following characters: +!()[].
As a reference, your code must ...
1
vote
2answers
503 views
Javascript function challenge add(1,2) and add(1)(2) both should return 3 [closed]
A friend of mine challenged me to write a function that works with both of these scenarios
add(1,2) // 3
add(1)(2) // 3
My instinct was the write an add() function that returns itself but I'm not ...
21
votes
13answers
1k views
Fastest gun of the west, king of the hill challenge
This is a King of the Hill challenge in a round robin. It's a battle to find the best gunman of the west!
To be able to compete in this contest you need to make two functions. The first one sets the ...
0
votes
1answer
150 views
Improving a Rubik's Cube scrambler's byte count
Okay, I recently wrote a Javascript Rubik's Cube scrambler that outputs a 25-move scramble. It's 135 bytes. The Gist is here, but for reference, I have the formatted code:
function(){
...
37
votes
5answers
2k views
Block Building Bot Flocks!
The contest is over!
Intro
This is an interactive king-of-the-hill contest where the controller is fully contained in a Stack Snippet at the bottom of the question. The controller automatically ...
10
votes
4answers
809 views
Capture The Flag
This is a game of capture the flag, heavily inspired and based off of Red vs. Blue - Pixel Team Battlebots. That was an awesome question (thank you very much Calvin'sHobbies; I hope you don't mind ...
106
votes
22answers
7k views
Red vs. Blue - Pixel Team Battlebots
This contest is officially over. The Blue Team won!
I autoran two sets of 50 battles and amazingly, Blue won all 100 of them. Looking at the stats, it is clear that the cooperative entries of ...
3
votes
6answers
2k views
Print all odd numbers from 0 to 100000
My teacher gave me a simple problem which I should solve with a code tiny as possible. I should print all odd numbers from 0 to 100000 into a HTML document using javascript.
for(var y = 0; y < ...
-3
votes
1answer
432 views
Append element to array only if it exists?
I know that, given an array a and an element e, a.push(e) appends it. However, consider an object o and the following code:
// o = {...}
var a = [o.one];
a.push(o.two);
Assuming o.one = 1 and o.two ...
0
votes
4answers
527 views
JavaScript: Tricks to shorten onkeydown, setInterval etc
Are there any tricks to shorten defined function names like setInterval, onkeydown, onkeyup, createLinearGradient or even return?
When using it more than once it's nice to put it as a string into a ...
103
votes
26answers
7k views
Making Future Posts Runnable Online with Stack Snippets
Stack Snippets were recently added to PPCG! Reminiscent of JSFiddle, Stack Snippets allow HTML, CSS, and JavaScript to be run directly in posts!
Here is a very simple Stack Snippet:
alert('This ...
4
votes
1answer
452 views
Javascript: Mini Space Invaders
I'm pretty new to code golfing, so I gave one of my first shots to a space invader clone called "Invas!on". It's a little less than 500 bytes, fully ASCII generated, and covers moving around and ...
0
votes
2answers
158 views
Move the “post your answer” form next to the question on SE sites
I have a problem when posting an answer to a question that already have several answers and/or several comments:
The "post your answer" form sits on bottom, the answer is on top. There is an awful ...
6
votes
2answers
764 views
¿Yo Quiero jQuery?
The Setup
You are given a simple web page with 11 elements:
10 input elements with IDs i1 thru i10, in order
one output element with ID out
The input elements have value attributes defined in the ...
3
votes
1answer
930 views
multiplication table in javascript [duplicate]
This javascript code:
for(x=1;x<6;x++)for(y=1;y<6;y++)console.log((y==1?'\n':'')+x+'*'+y+'='+x*y);
prints the following:
1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
3*1=3
...
16
votes
4answers
1k views
Program a 2048 AI using an existing Framework
EDIT : Recently, my question has been proposed as a duplicate of 2048 Bot Challenge. I would like to stress that this question is different from that question, and will require answers to be ...
40
votes
19answers
2k views
Tips for Golfing in ECMAScript 6
This is similar to other "Tips for golfing in <...>" but specifically targeting the ECMAScript 6 features in JavaScript.
JavaScript inherently is a very verbose language, function(){}, .forEach(), ...
8
votes
3answers
661 views
Forcing the Horse
This is a simple one: create the shortest browser script to change every appearance of force on a web page into horse. This script needs to be able to be pasted into the console and work on most ...
-2
votes
2answers
371 views
Linking without a Link
Introduction
Hello! This is my second post, and I decided to do one which is more language specific, since my last one was very much orientated towards mathematical languages, and thus did not leave ...
0
votes
2answers
816 views
Babylon.js - loop through a scene and apply a simple fragment shader to all of the objects
You have a library - a fully loaded 2014 Babylon.js.
You have a fragment shader - let's call it sample.fragment.fx.
You have a scene - loaded ahead of time, possibly from a .babylon JSON file.
Your ...
3
votes
5answers
415 views
Increment Bitwise
Make a function that increments a number using only bitwise, loops, and conditions.
Rules:
All entries must be as per the language spec defined below.
Scoring is not of code length, but of the ...
1
vote
3answers
2k views
Check If Two or More Variables Are All Equal to Zero in JavaScript
What is the shortest way to check if two or more variables are equal to 0 in JavaScript?
I'm curious to know if there's something shorter than if(!x&&!y&&!z){...}.
16
votes
5answers
3k views
2048 Bot Challenge
We have been cloning 2048, analyzing 2048, but why haven't we played it yet? Write a 555 byte javascript snippet to play 2048 automatically, the best score after an hour will count (see scoring ...
5
votes
2answers
367 views
2D javascript table graphics
The challenge
Make a JavaScript program that can use a HTML table as a canvas, having each cell a pixel.
You can either input the position and color values in a form or by using the console.
Score ...
7
votes
3answers
429 views
Refactor variable names in JavaScript code
Your challenge today is to refactor JavaScript code. You will take three strings as input; a JavaScript string, a old variable name, and the name you want to refactor it to. For example, an input of
...
11
votes
1answer
592 views
JavaScript load and SHA-256
This is a code golf puzzle with a real-world application. Some current browsers, if you enter a URL that looks like
data:text/html,<script>alert("hi")</script>
will execute the given ...
19
votes
3answers
1k views
JSFuck Golf - Hello World
JSFuck is an esoteric language in which any Javascript statement can be accurately reproduced into another valid Javascript program that uses only the 6 characters []()!+.
The JSFuck converter, when ...
1
vote
1answer
612 views
Compressing a DNA-like string [closed]
my app is multiple choice test, where for each question the response results in a 4 letter string "eg" GTAC or ATGC or CATG, etc. There are always just 24 questions. so the final result is something ...
0
votes
3answers
3k views
javascript: smallest code to convert seconds to time [closed]
Given seconds like 11728, write the smallest javascript function that returns a string like 3hrs. 15min. 28sec.
signature textTime([int] t,[bool] z,[bool] m)
t is the time like 11728 and you can ...
27
votes
11answers
2k views
Make StackOverflow Explode (bookmarklet) [closed]
Sometimes people get frustrated on the StackExchange network (specifically SO).
Your task is to create a bookmarklet that causes StackOverflow to explode/implode/destroy in some fashion. This will ...
7
votes
4answers
632 views
Display a bézier curve in the browser
The goal is to display a bézier curve in any classical browser (except maybe old IE versions, because... are they really browsers?) client side.
Rules:
You must provide one or more files (or their ...
8
votes
2answers
288 views
Write the shortest text getter/setter on an element for the DOM
Just like jQuery's $.fn.text, write one or two functions that can get and set the text on an element.
You can't use textContent or innerText, and even less innerHTML.
Plain javascript. No DOM ...
-2
votes
1answer
249 views
IPv4 “in subnet” function [closed]
Implement the following JavaScript method as short as possible:
function same_subnet(ip_a,ip_b,sn_mask)
{
}
It should get 2 IP addresses and a subnet mask. It should return true if ip_a and ip_b ...
1
vote
10answers
2k views
Convert JSON string to Key / Value Arrays
Convert JSON (key/value pairs) to a native arrays of keys & values, in your language.
var X = '{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}';
The value array could be ...
2
votes
10answers
823 views
Implement String.prototype.toLowerCase()
Implement String.prototype.toLowerCase()
Description
The toLowerCase method returns the value of the string converted to lowercase. toLowerCase does not affect the value of the string itself.
...
18
votes
20answers
3k views
Javascript: Create a 10x10 array of 1s
Obviously this challenge would be trivial with separate functions and libraries, so they aren't allowed.
Your code must conform to an ECMAscript specification (any spec will do), so no ...
2
votes
3answers
8k views
Shortest code to check if a number is in a range in JavaScript
This is how I checkout to see if a number is in a range (in between two other numbers):
var a = 10,
b = 30,
x = 15,
y = 35;
x < Math.max(a,b) && x > Math.min(a,b) // -> ...
1
vote
4answers
2k views
Make an HTML page goto infinite loop?
Write a code using HTML, JavaScript, jQuery to make the page go into infinite loop.
Restrictions:
No looping or control structures of javascript and jQuery allowed. You can only use alert, events, ...
67
votes
61answers
14k views
Tips for golfing in JavaScript
What general tips do you have for golfing in JavaScript? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to JavaScript (e.g. "remove ...
4
votes
2answers
1k views
Smallest Javascript CSS Selector Engine [closed]
Create a small acceptably efficient JS CSS selector engine. Standard css 2.0 properties should be supported in Firefox 3.0+,Safari , Opera, IE7+, and extra brownie points for IE6 support.
Smallest ...
43
votes
3answers
3k views
What can you do in a 4k data URI?
Bounty is over, thephpdeveloper wins with Conway's Game of Life
The web platform today is advancing at a rapid rate. Features like CSS3 animations, transforms, drop shadows and gradients, ...
15
votes
4answers
21k views
Shortest URL regex match in JavaScript
Create the shortest regular expression that will roughly match a URL in text when run in JavaScript
Example:
"some text exampley.com".match(/your regular expression goes here/);
The regular ...