nderscore
  • Member for 7 years, 9 months
  • Last seen more than a month ago
Deletion of a blank line in source code which causes unexpected functionality
62 votes

Javascript Opens an alert popup with "Hello, World!" if the blank line exists, otherwise alerts "0". (function(){ alert(~(arguments.callee+[]).indexOf('\n\n') && "Hello, World!"); })(); ...

View answer
Output Pi without math
42 votes

JavaScript (ES5) 20 bytes A variation of m.buettner's JS solution. (x='.'+0xE).length+x Edit: JavaScript (ES5) 18 bytes A variation of ComFreek's idea of using the base64 decode function. atob('...

View answer
Help!! How to do square root!
28 votes

JavaScript Unfortunately, JavaScript does not support the square root symbol for function names. Instead, we can use some other Unicode alphabet character to represent a square root function. In ...

View answer
Fast, Cheap, and Good - Choose any Two
Accepted answer
23 votes

Javascript (ES5) with jQuery - 143 (Demo) I modified Matt's solution and golfed it as far down as I think it can go: $("*").html(["SELECT ANY TWO","FAST","GOOD","CHEAP"].join("<input type=...

View answer
Draw an asterisk analog clock for hour N
18 votes

Javascript (ES6), 105 76 65 bytes F=N=>` * ab*12 9@3 87654`.replace(/\w/g,y=>'0x'+y^N%12?' ':'*') <!-- Snippet Demo: --> N = <input type="number" min="0" max="24" value="2" ...

View answer
Play the "bzzt" game
16 votes

Javascript 50 49 -1 byte thanks to core1024 for(i=0;i++<500;)alert(i%3*!/3/.test(i)?i:'bzzt')

View answer
Write a program that downloads itself
15 votes

JavaScript - 123 122 101 95 92 91 87 86 114 with(new XMLHttpRequest)send(open(0,/\codegolf.stackexchange.com\posts\28175\body/,0)),alert(/w.*/.exec(response)) Runs in the console of your web browser ...

View answer
Convert JSF**k to normal JS
Accepted answer
13 votes

Javascript - 68 55 51 alert(/\n(.+)/.exec(eval(prompt().slice(0,-2)))[1]) Alternatively: (same length) alert(/.+(?=\n})/.exec(eval(prompt().slice(0,-2)))) Runs in the console of your browser. Only ...

View answer
ASCII Art of the Day #1 - Double Knot
12 votes

Javascript (ES7 Draft), 169 163 160 158 bytes Edit: -6 by using a template string to eliminate some repetition from the pattern string. Edit: -3 by switching from slice(0,-2) to slice(2) by ...

View answer
Vacancy or no vacancy?
11 votes

Javascript (ES6), 60 bytes (Open your browser's console while running the snippet to see the colored result.) f= n=>console.log((n>199?'%cNO':'NO%c')+' VACANCY','color:red') <input ...

View answer
ETAOIN SHRDLU golf
11 votes

Javascript (ES6) 119 117 Edit: (-2) Removed the need for toUpperCase using a case-insensitive RegEx in the split call. a=prompt(f=x=>a.split(RegExp(x,'i')).length) alert([...'...

View answer
Capitalize first letter of each word of input
10 votes

Javascript (ES6), 77 bytes alert(prompt().split(' ').map(x=>x&&x[0].toUpperCase()+x.slice(1)).join(' ')) Commented alert( // output prompt(). // take input split(' '). //...

View answer
Convert 1, 2, 3, 4, 5, 6, 7, 8, and 9 to "one", "two", "three", etc
10 votes

Javascript 73 alert('0one0two0three0four0five0six0seven0eight0nine'.split(0)[prompt()]) 69 alert(btoa("ôéÞõ5õ1ëxO_¢êý|Þöȱõ'xß^hSôا{Ý").split(9)[prompt()])

View answer
Words that Contain Digits
9 votes

Javascript (ES6), 101 99 bytes f= s=>-~'ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE'.split` `.findIndex(x=>s.match([...x].join`.*`)) <!-- snippet demo: --> <input list=l ...

View answer
Loading Forever... Windows style
8 votes

Javascript (ES6), 86 bytes setInterval('with(console)clear(),log(`[${x=x[9]+x.slice(0,9)}]`)',100,x='... .')

View answer
Pi Day, Pi Minute, or Pi Second?
8 votes

Javascript (ES6), 114 112 - 15 = 97 bytes x=>['Pi Day','Pi Minute','Pi Second'].find((x,i)=>[/ar 14/,/(03|15):14:/,/03:14/][i].test(Date()))||'No Pi Time' Ungolfed: x=> ['Pi Day', 'Pi ...

View answer
Good Versus Evil
8 votes

Later is Evil, JavaScript (node.js) Measures the amount of time between executions. If the the time difference is greater than last time, it must be evil. Otherwise, good. var fs = require('fs'), ...

View answer
The shortest code to invert bit-wise a binary string
7 votes

Javascript (ES6) 36 alert(prompt().replace(/./g,x=>x^1))

View answer
La La Land... no wait, Moo Moo Moonlight
6 votes

Javascript (ES6), 38 bytes x=>(y=/.*?[aeiouy]+/i.exec(x)+' ')+y+x f= x=>(y=/.*?[aeiouy]+/i.exec(x)+' ')+y+x <!-- snippet demo: --> <input list=l oninput=console.log(f(this....

View answer
Fake Marquee Text
6 votes

Javascript (ES7 Draft), 61 bytes f=(s,l)=>[x.substr(i,l)for(i in x=' '.repeat(l)+s)].join(` `) <input id="str" value="Some String" /> <input id="num" value="5" /> <button ...

View answer
Sourcecode selfie
6 votes

Javascript (ES6), 72 bytes 16 unique alphanumeric character pallete: fjalert0plcgmixn (f=j=>alert(`(f=${f})(0)`.replace(/./gmi,x=>' '.repeat(j++)+x+'\n')))(0) m and i flags are added ...

View answer
Calculator that adds char values
6 votes

Javascript (ES6) 51 alert([...prompt(x=0)].map(y=>x+=y.charCodeAt())|x)

View answer
Fizz Buzz Lightyear
5 votes

Javascript (ES6), 182 175 bytes -7 bytes: Moved Buzz Lightyear logic into Buzz ternary expression. f=(n,s=i=b=_='')=>i++<n?f(n,s+`${(i%3?_:'Fizz')+(i%5?_:`Buzz${++b%3?_:` Lightyear, Space ...

View answer
Write a program to elasticize strings
5 votes

Javascript ES6, 39 bytes x=>x.replace(/./g,(y,i)=>y+y.repeat(i)) Same length, but more fun: x=>x.replace(i=/./g,y=>y.repeat(i=-~i)) Snippet demo: f= x=>x.replace(/./g,(y,i)=>...

View answer
Expand an encoded string
5 votes

Javascript (ES6), 86 83 bytes alert(prompt().replace(/(.+?)(\d)(?!\d)/g,(a,b,c)=>b.replace(/./g,y=>y.repeat(c)))) Commented: alert( // output final result prompt(). // take input ...

View answer
Minimalist Hex Clock
5 votes

HTML/CSS/JavaScript 207 183 180 161 152 Tested and working in the latest Firefox and Chrome browsers. <body id=b onload=setInterval("b.innerHTML=b.bgColor=Date().replace(/.*(..):(..):(..).*/,'#$1$...

View answer
Let's move the Mars rover!
5 votes

Javascript (ES6) 145 141 127 Edit: Removed the need for a translation array using method from edc65's C solution [x,y,d]=(p=prompt)(s='NESW').split(','),[...p(d=s.search(d))].map(c=>c!='M'?(d+=c&...

View answer
Hash collision: "NO" means "YES"
5 votes

Javascript (ES6) 54 bytes f=s=>[x.charCodeAt()for(x of s)].join('')^7879||897296 f('YES'); // 897296 f('NO'); // 897296 f('MAYBE'); // -824036582

View answer
Blink the webcam light!
4 votes

Javascript (ES6), 100 bytes (f=_=>navigator.getUserMedia({video:1},x=>s(_=>x.getTracks()[0].stop(s(f,500)),500),s=setTimeout))() During my testing, I saw a delay between the camera being ...

View answer
Convert Brainfuck to a Non-Golfing Language
4 votes

Javascript (ES7 Draft), 170 bytes Function which compiles BF source code into Javascript. The resulting code accepts input via prompt() and outputs via alert(), both one character at a time. f=x=>...

View answer