Skip to main content
Commonmark migration
Source Link

Javascript ES6 (REPL), 52 bytes

var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();

#Javascript ES6 (REPL), 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); InitialInitial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

Explanation

#Explanation BasedBased on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

#Javascript ES6 (REPL), 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

Javascript ES6 (REPL), 52 bytes

var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();

Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

Explanation

Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

added 7 characters in body
Source Link
Mama Fun Roll
  • 9.9k
  • 1
  • 36
  • 46

#Javascript ES6 (REPL), 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

#Javascript ES6, 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

#Javascript ES6 (REPL), 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

added 282 characters in body
Source Link
Mama Fun Roll
  • 9.9k
  • 1
  • 36
  • 46

#Javascript ES6, 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

This exploits the fact that var a||'' coerces the value at a to an empty string if it isn't defined; otherwise, undefineda so that callingis left as is. a inwill store our final result.

Each function call, a?2:1 won't throw an errorwill be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

To extendThe last function call will output the payloadfinal value of (`$=${$};$()`a) after finishing.

#Javascript ES6, 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

This exploits the fact that var coerces the value at a to undefined so that calling a in a?2:1 won't throw an error.

To extend the payload (`$=${$};$()`)

#Javascript ES6, 52 bytes var a=a||'';$=_=>a+=$=${$};$();.repeat(a?1:2);$(); Initial working implementation, may be golfable.

y.onclick=_=>z.innerText=eval("var a=a||'';$=_=>a+=`$=${$};$();`.repeat(a?1:2);$();".repeat(x.value))
<input id=x><button id=y>Submit!</button><pre id=z></pre>

#Explanation Based on my usual quine implementation ($=_=>`$=${$};$()`;$()).

var a||'' coerces a to an empty string if it isn't defined; otherwise, a is left as is. a will store our final result.

Each function call, a will be checked to see if it is empty/falsy. The first function call will append 2 copies of the quine because a is empty; subsequent calls will only append 1 copy because a is no longer empty.

The last function call will output the final value of a after finishing.

added 282 characters in body
Source Link
Mama Fun Roll
  • 9.9k
  • 1
  • 36
  • 46
Loading
Source Link
Mama Fun Roll
  • 9.9k
  • 1
  • 36
  • 46
Loading