Skip to main content
57 votes

Reserved JavaScript

37 words ...
tsh's user avatar
  • 36.2k
57 votes

Reserved JavaScript

43 words, 603 bytes Uhm, is this a loophole? I have no idea how the hell this is legal JS, but it works and it uses every single keyword. ...
Siguza's user avatar
  • 779
36 votes

Reserved JavaScript

43 words, 302 299 bytes ...
l4m2's user avatar
  • 32.7k
36 votes
Accepted

Get string "-" with JavaScript using only the symbols from "+[]"

260 ... 210  205 bytes Saved 5 bytes thanks to @user202729 ...
Arnauld's user avatar
  • 206k
33 votes

xkcd 2385 KoTH (Final Exam)

Game Theory is stupid anyway { name: "Game Theory is stupid anyway", run: _ => 100 } Senioritis hits hard sometimes.
hakr14's user avatar
  • 5,532
29 votes

xkcd 2385 KoTH (Final Exam)

Balanced Strategy What could be more balanced than returning all of the numbers? Rotates by one after every game. ...
New Posts's user avatar
  • 399
27 votes

xkcd 2385 KoTH (Final Exam)

FunnyNumber { name: "FunnyNumber", run() { return 69 } } Somebody has to do it.
SjoerdPennings's user avatar
27 votes
Accepted

xkcd 2385 KoTH (Final Exam)

Offset Prediction I'd made a bot that just optimizes for the moving average of the averages (which worked reasonably well), and while testing I noticed that the actual averages seem to jump around the ...
gsitcia's user avatar
  • 3,456
26 votes

Tips for golfing in JavaScript

Abuse literals The recent sample: Check whether "c" is uppercase or lowercase, doesn't matter if not letter ...
l4m2's user avatar
  • 32.7k
26 votes
Accepted

Can `a?b<c:b>c` be shortened in Javascript?

Yes, it can be shorter! c-b<a^a beats a?b<c:b>c by 2 bytes. My tests show that it works for any integer, including ...
dingledooper's user avatar
  • 23.4k
25 votes
Accepted

Is it possible to make a clamp function shorter than a ternary in JS?

20 bytes For reference, this is the original version without whitespace and without naming the function: n=>n>0?n<255?n:255:0 Try it online! 19 bytes We ...
Arnauld's user avatar
  • 206k
24 votes

xkcd 2385 KoTH (Final Exam)

getRandomNumber ...
Aaroneous Miller's user avatar
23 votes

xkcd 2385 KoTH (Final Exam)

Max Max. { name: "Max", max: "max", run:(max)=> Math.max(...max) }
Razetime's user avatar
  • 27.6k
22 votes

xkcd 2385 KoTH (Final Exam)

Sam (Self-Aware Maximizer) Finds the output cybersecurity score that maximizes the total score including the own output in the mean. Assumes that the sum of all other bots' scores is going to be the ...
wimi's user avatar
  • 321
21 votes

xkcd 2385 KoTH (Final Exam)

Copycat Copycat is a dumb bot. Therefore, it's likely a random bot is smarter than it. Therefore, copying off another bot is a good idea. I think. ...
rydwolf's user avatar
  • 19.3k
19 votes

WTF.js Obfuscator

JavaScript (ES6),  139  135 bytes ...
Arnauld's user avatar
  • 206k
19 votes

Shortest way to coerce to array

10 bytes [s].flat() This works by doing a shallow flat on [s]. So, if s is anything other ...
rydwolf's user avatar
  • 19.3k
17 votes

Creating a function over multiple lines

35 Lines f= 0[ c= '\ c\ o\ n\ s\ t\ r\ u\ c\ t\ o\ r' ][ c] ` r\ e\ t\ u\ r\ n\ '\ b\ a\ r\ b\ a\ r\ i\ a\ n' ` Try it online! Uses the fact that ...
Bubbler's user avatar
  • 79.3k
17 votes

WTF.js Obfuscator

I have a solution which works if you have infinite time and memory. I'm not 100% sure whether that's allowed within the rules here; I searched on codegolf.meta.SE and didn't find anything saying that ...
kaya3's user avatar
  • 549
17 votes

xkcd 2385 KoTH (Final Exam)

Histogrammer This bot keeps track of how often different averages have occurred, rounded to the nearest integer, to approximate their probability distribution. Using this, it attempts to choose the ...
DanTheMan's user avatar
  • 4,105
16 votes

Gold Battle KoTH

Unkillable forked from Undyable. ...
Draco18s no longer trusts SE's user avatar
15 votes

Prisoner's Dilemma with access to opponent

BoomBot function boom(them) { throw 1; } If the opponent is run first and calls this without try..catch, this bot ...
Bubbler's user avatar
  • 79.3k
15 votes

xkcd 2385 KoTH (Final Exam)

Crb Crab has now learned how to hack, and is still not playing nice { name: "Crb", run() { return 1 } }
caird coinheringaahing's user avatar
15 votes

xkcd 2385 KoTH (Final Exam)

Follow the Leader Figure out which bot had the highest combined score last round, then do what they did. ...
MJ713's user avatar
  • 271
14 votes

Tips for golfing in JavaScript

Converting an array of strings into numbers Take the array ["32", "0x30", "0o10", "7.642", "1e3"]. The simple way ...
rydwolf's user avatar
  • 19.3k
14 votes

Get string "-" with JavaScript using only the symbols from "+[]"

286 256 251 247 244 240 bytes ...
Kevin Cruijssen's user avatar
14 votes

xkcd 2385 KoTH (Final Exam)

Random 50-90 If the average is \$m\$, the optimal play is \$50+0.4m\$. If we assume the average is uniformly distributed over \$[0, 100]\$, the optimal play is uniformly distributed over \$[50, 90]\$. ...
Robin Ryder's user avatar
  • 15.8k
13 votes

Formic Functions - Ant Queen of the Hill Contest

Windmill Here's a windmill... waiting for the Man from la Mancha (or Vampire from la Mancha?) who will ride up to bring it down. I tried to explore how much further the design of Miners on a Rail - ...
GNiklasch's user avatar
  • 261
13 votes

Art Attack KoTH

Jim ...
dzaima's user avatar
  • 20.3k
13 votes

xkcd 2385 KoTH (Final Exam)

Calculus ...
Bubbler's user avatar
  • 79.3k

Only top scored, non community-wiki answers of a minimum length are eligible