Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [javascript]

This challenge is related to the JavaScript language. Note that challenges that require the answers to be in a specific language are generally discouraged.

0
votes
2answers
130 views

Map an array of functions to their return values in point-free style

Introduction I have some JavaScript code that uses Array.prototype.map to map an array of functions fns to their return values: ...
-5
votes
1answer
142 views

split a string with two types of groups, ignoring characters in one [closed]

Example inputs and outputs: Input 1 "request.partner" Output 1 [request, partner] Input 2 ...
41
votes
9answers
6k views

Reserved JavaScript

As of ECMAScript 2015, JavaScript has 33 reserved keywords, such as break, const and new, as ...
7
votes
2answers
460 views

Creating a function over multiple lines

I'm attempting to create a function over multiple lines. Parameters of the challenge: Function returns 'barbarian' Only 2 characters per line 40 lines maximum. I keep trying to use a fat arrow to ...
13
votes
2answers
497 views

How to solve the total task on “return true to win” in 21 chars

There is a site called "Return True to Win" with interesting tasks for Javascript programmers. The goal is to find arguments to a given function that force it to return true. The following is one of ...
0
votes
0answers
78 views

Techniques for making code smaller [duplicate]

I came across dwitter which is a twitter for coding javascript ni 140 chars. I saw some cool things people do there for reducing the size of the code, for instance: ...
3
votes
2answers
351 views

Golfing Newton's Method

I have the following code which I've written to emulate Newton's method for deriving the square root of a number: ...
99
votes
31answers
9k views

Formic Functions - Ant Queen of the Hill Contest

Watch live | Active answers | Add new answer | Chat room | Source code | Leaderboard New tournaments whenever needed. New players and new updates very welcome. Not actual game footage. Each player ...
4
votes
3answers
269 views

Compare char to other chars in javascript

In my answer, I have this code: s.match(/[AEIOU]/) This seems too verbose to check if a string is one of A, ...
9
votes
1answer
338 views

Tip? Short way to generate up to 12 repeated characters in JavaScript

'---------' '-'.repeat(9) // longer! '------------' (x='----')+x+x '-'.repeat(12) // same length Is there any cleverer way of generating strings of up to 12 ...
5
votes
2answers
386 views

How to simplify ternary expressions in Javascript

I have an expression that could be expressed as either of : a += (A ? B ? x : C ? y : D : D); a += (A && B ? x : A && C ? y : D); where A,B,C ...
28
votes
6answers
1k views

Team of The Hill!

This challenge was inspired by @HelkaHomba's excellent challenge Red vs. Blue - Pixel Team Battlebots. That challenge was probably the best one I've seen on this site. Ever. My challenge is still a ...
4
votes
0answers
182 views

λ-calculus to js arrow notation transpiler [closed]

Not an interpreter. Arguably a compiler. But I'm talking about a transpiler. It can be in any language, but it must return js-valid arrow notation code. The λ-calculus string would be passed as an ...
-10
votes
1answer
266 views

Shortest possible JS (ES5) code to get ids of all elements of a given tag

Using the shortest JS (ES5) code possible, as measured in number of characters, gather all the ids on a page for foobar elements into a comma-delimited string. For ...
10
votes
0answers
192 views

“Could you repeat yourself?” aka Could a doubled character solution exist in JavaScript? [duplicate]

This thinking exercise is inspired from Super Chafouin's question "Just Repeat Yourself" in which the phrase "Do not repeat yourself!" had to be outputted using code that was basically a series of ...
6
votes
1answer
283 views

Javascript tips: 2 to the power of x multiplied by n

I'm new to ES6 and code-golfing. Here's the original function: function puzzle(n, x) { return n * Math.pow(2, x); } And here's what I have so far: <...
15
votes
2answers
1k views

Is there a way of shortening fat-arrow functions?

From what I've seen throughout my time here on PPCG, most JavaScript entries involving fat arrow functions tend to be one of two camps: The simple ones that are capable of running as a single ...
1
vote
1answer
142 views

JSON tips: filter objects from array of objects where object name is alpha [closed]

What could be the shortest code for filtering the following array in Javascript without any library? My code is: filtered_obj = _.where(obj, { name: "Alpha" }); ...
2
votes
5answers
769 views

Include a JavaScript script with JavaScript

To dynamically include a JavaScript file in a web page, you'd normally insert a <script> tag pointing to your script. For example: ...
0
votes
1answer
229 views

Needs more jQuery! [closed]

Inspired by this site, this question could potentially be a doozie. People on StackOverflow often overuse jQuery as an answer. Therefore, we need a way to recognize programmatically if a code snippet ...
24
votes
8answers
897 views

KOTH: Everybody loves tokens

In this game two players compete to eat the most points worth of tokens, but there's a twist! Eating multiple tokens in a row of the same color gives an ever-growing bonus, but watch out, or your ...
46
votes
2answers
1k 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 ...
17
votes
3answers
8k 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 ...
62
votes
23answers
3k 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 up ...
19
votes
6answers
1k 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: ...
1
vote
2answers
1k 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() ...
22
votes
13answers
2k 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 ...
1
vote
1answer
191 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: ...
41
votes
5answers
3k 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 ...
11
votes
5answers
1k 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 ...
128
votes
22answers
10k 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 ...
5
votes
6answers
3k 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. ...
2
votes
4answers
687 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 ...
130
votes
28answers
10k 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: ...
5
votes
1answer
581 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 ...
1
vote
2answers
250 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 ...
8
votes
2answers
893 views

¿Yo Quiero jQuery?

The Setup You are given a simple web page with 11 elements: 10 input elements with IDs i1 thru ...
4
votes
1answer
2k 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: ...
17
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 thought ...
76
votes
34answers
8k views

Tips for Golfing in ECMAScript 6 and above

This is similar to other "Tips for golfing in <...>" but specifically targeting the newer features in JavaScript brought up in ECMAScript 6 and above. JavaScript inherently is a very verbose ...
8
votes
3answers
747 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
404 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 ...
1
vote
2answers
1k 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
485 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 ...
3
votes
3answers
4k 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 ...
19
votes
5answers
4k 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 below)....
5
votes
2answers
858 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
546 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 <...
14
votes
1answer
1k 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 ...
19
votes
3answers
2k 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 ...