Skip to main content
Share Your Experience: Take the 2024 Developer Survey
57 votes

Reserved JavaScript

37 words ...
tsh's user avatar
  • 34.9k
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

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

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

Reserved JavaScript

43 words, 302 299 bytes ...
l4m2's user avatar
  • 24.4k
34 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
  • 4,974
32 votes
Accepted

JSF**k with only 5 symbols?

After brainstorming, the result seems to be that, on modern browsers at least, there’s no way to do this. I’ll try to summarize the entire process, adding some reasoning about why we’ve exhausted our ...
lynn's user avatar
  • 68.7k
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
  • 391
28 votes

Tips for golfing in JavaScript

Use ^ instead of != or == when comparing to an integer ...
Tomas Langkaas's user avatar
27 votes

xkcd 2385 KoTH (Final Exam)

FunnyNumber { name: "FunnyNumber", run() { return 69 } } Somebody has to do it.
SjoerdPennings's user avatar
26 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,301
25 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
  • 24.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
  • 193k
25 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
  • 22.7k
23 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
  • 331
23 votes

xkcd 2385 KoTH (Final Exam)

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

xkcd 2385 KoTH (Final Exam)

Max Max. { name: "Max", max: "max", run:(max)=> Math.max(...max) }
Razetime's user avatar
  • 27.2k
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 Programs's user avatar
20 votes

Formic Functions - Ant Queen of the Hill Contest

Forensic Ants All my answers are sharing the same set of low-level helper functions. Search for "High-level logic begins here" to see the code specific to this answer. ...
Dave's user avatar
  • 8,479
19 votes

Formic Functions - Ant Queen of the Hill Contest

Sliding Miners 6.4 ...
dzaima's user avatar
  • 20.3k
19 votes

WTF.js Obfuscator

JavaScript (ES6),  139  135 bytes ...
Arnauld's user avatar
  • 193k
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 Programs's user avatar
18 votes

JSF**k with only 5 symbols?

The 3 functions in Lynn's answer weren't that useless. But the strict mode in ECMAScript 5 foiled my plan. There is a quirk in the older versions of JavaScript / ECMAScript. If a method is called ...
jimmy23013's user avatar
18 votes
Accepted

Is there a way of shortening fat-arrow functions?

Use Recursion I've found that recursion is (almost) always shorter than eval+for. The general way to convert from for to eval ...
Downgoat's user avatar
  • 29k
18 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,115
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
16 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
  • 76.8k
16 votes

Gold Battle KoTH

Unkillable forked from Undyable. ...
Draco18s no longer trusts SE's user avatar
16 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
  • 281
15 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.6k
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 coinheringaahin g's user avatar

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