
Return True to Win - moklick
http://alf.nu/ReturnTrue
======
fauria
This table is quite useful to solve some problems:
[https://dorey.github.io/JavaScript-Equality-
Table/](https://dorey.github.io/JavaScript-Equality-Table/)

~~~
liquidise
> _Moral of the story: Always use 3 equals unless you have a good reason to
> use 2._
    
    
      NaN === Nan  // => false
      [] === []    // => false
      {} === {}    // => false
      [1] === [1]  // => false
      [0] === [0]  // => false
    

I guess i never see the gains in the triple vs double equal sign wars.

~~~
idbehold
Do any of those return true if you use double equals? The distinction only
really comes up when you have to different types on either side and then It
will coerce one of the types to match the other.

~~~
TAForObvReasons
That is correct. The canonical example is string-numeric coercion:

    
    
        "0" == 0 && "0" !== 0

------
apricot
Find the exact combination of browser/OS that does more than show "return true
to win" on a white background to win.

~~~
wtbob
> Find the exact combination of browser/OS that does more than show "return
> true to win" on a white background to win.

I see:

    
    
        return true to win
        
        (Come back in a few minutes.)
    

What do I win?

~~~
throwanem
A moment in which to reflect.

------
qwertyuiop924
I already saw this on lobste.rs, but it's still cool. I like ES just fine, but
to think we could have had scheme instead. Gee, thanks Netscape:

Every time you win, everybody loses.

~~~
ninjakeyboard
"it's because of you, motherfucker, that we're not all using lisp" @ 5:00
[https://www.youtube.com/watch?v=bzkRVzciAZg](https://www.youtube.com/watch?v=bzkRVzciAZg)

~~~
qwertyuiop924
No, that's actually the fault of Netscape.

Anyways, that video is awful and totally wrong. Node code can be clean,
threaded code can be ugly. Both can be fast, but the perf characteristics are
different (for OS threads, anyways).

------
nfriedly
It loaded for me eventually. First one is pretty straightforward. After that
they seem to require knowledge of JavaScript quirks.

------
ninjakeyboard
I don't exactly know what I did, but it did say that I win.

~~~
junke
A day like any other with Javascript ;-)

~~~
noobermin
s/with Javascript/being alive/

------
idbehold
Let me document all the reasons I dislike the HTML spec: it defines a willful
violation of the ECMAScript standard.

~~~
xeniak
Can you elaborate?

~~~
fennecfoxen
I'll use a link shortener to prevent spoilers. This link elaborates exactly
which rules are abused: [https://goo.gl/mu5xtr](https://goo.gl/mu5xtr)

"These requirements are a willful violation of the JavaScript specification
current at the time of writing. The JavaScript specification requires that
ToBoolean return true for all objects, and does not have provisions for
objects acting as if they were undefined for the purposes of certain
operators. This violation is motivated by a desire for compatibility..." with
old Internet Explorer.

------
sirsuki
TypeError: NetworkError when attempting to fetch resource.

Maybe the challenge is to fix HTTP?

------
unsignedqword
Does anybody really know why JS's type system was designed the way it was? It
seems so out of whack with what people want out of a language, dynamically
typed or otherwise.

~~~
curveship
It's because Eich was told to make JS C-like. In C, an empty array, an empty
string, 0, false and null are all the same value: a word with all bits 0. So
in JS, those are all are falsy and == to each other.

~~~
jomamaxx
I wish an empty string was not false.

In 'object' terms, an empty string is still a string! It's something.

I guess if you think about it from a memory perspective, it's 'nothing'.

But since JS is not actually like C, I really wish "" were true.

~~~
nv-vn
"" is actually true in C, but that's also because it represents something in
memory. Consider how C encodes strings: an empty string is a _pointer_ to a 0
(or a '\0', if you want to think of it as a char). However, the pointer (being
an address) is non-zero (since the address 0 is NULL).

~~~
jomamaxx
touché

------
xyclos
This is a nice challenge to start the morning.

However, on mobile the input loses focus after each individual character typed
which is quite frustrating.

------
billpg
I typed "true", without the quotes.

Did I do it wrong?

~~~
marxidad
It's code golf. Try to do it in less than 4 characters.

------
dou4cc
The game shows us how ugly JS is.

~~~
posterboy
Indeed, I refuse to believe there should be a solution to the 'reflexive'
task.

~~~
XaspR8d
So you disagree with the IEEE floating point specification, then? Javascript
is directly following spec there.

~~~
astrobe_
Does that spec forces you to implement equality test between floating point
numbers?

~~~
Zarel
...yes? I'm not sure exactly what you're asking here, though.

~~~
astrobe_
I'm asking if it is really a good idea for a language to provide
equality/inequality for floating point numbers when it's often mistake to do
that.

~~~
Myrmornis
So disallow the direct operator but allow equality to be deduced indirectly by
usage of > < >= <= ?

------
CGamesPlay
My gosh, this is way harder than the alert(1) series.
[http://escape.alf.nu](http://escape.alf.nu)

------
nxzero
Reminds me of "The Little Lisper" and coding koans; honestly thought it'd be
harder to "win" the challenge.

------
brudgers
Fri Aug 12 14:35:18 UTC 2016:

Page had message that the Hacker News 'hug' was likely to affect performance.

------
plank
Took me a couple of tries... (Spoiler): Anyone anything shorter then 4
characters (two characters)?

~~~
lma21
How did you solve the reflexive? I'm not getting at anything :(

~~~
kqr
NaN != NaN. It's how you're supposed to test for NaN, apparently.

~~~
madawan
Or use isNaN

~~~
kqr
I'll give you one chance to guess how isNaN is implemented.
[https://github.com/v8/v8/blob/e6d1a80e790117dc27b20e9b14de4b...](https://github.com/v8/v8/blob/e6d1a80e790117dc27b20e9b14de4b6ac9f7512f/src/js/macros.py#L90)

------
curveship
For the first 5, I've got 2,3,8,14,7. Anybody got tighter solutions?

~~~
esnard
I got 7 on the third challenge with that solution:

    
    
        transitive([],0,[])

------
sladix
Does someone have a <52 char solution for the counter one ?

~~~
curveship
(x=0)=>()=>++x

~~~
awalGarg
You can save one character by doing this:

(x=0)=>_=>++x

the underscore is another variable but a single variable does not require
parenthesis. So instead of two chars for the two parens, you use a single char
for a single letter variable. JS FTW ;)

------
stoic
With games like these I feel like we all lose

~~~
jomamaxx
This is true.

Pun intended!

------
lalala1995
Please more levels

~~~
idbehold
You've already finished wat, undef, random3, and random4?

~~~
fennecfoxen
> wat, undef

Oh, undef is as easy as knowing HTML trivia. Getting a falsey value to return
an arbitrary string when invoked as a function is at least a little harder...

> random3

... is almost as easy as random1

> random4

is exactly as impossible as it looks

------
agentgt
What is with the User/Score/Browser table? I only did like 4 of the tests and
that thing popped up. I would finish it but I have some other things to do.

~~~
Pfhreak
Looks like once you successfully score, it shows you how many characters it
took others to solve. For example, the first one you can trivially type in
true to solve it, with four characters. But it's solvable with only two
characters.

~~~
agentgt
Yes but there is no where you can enter your screen name. I should have
clarified that in my question because I got down voted for asking this.

The whole down voting thing imo really has to go. Just flag answers or up
vote. The whole bro intellectual rudeness is sort of off putting.

------
Zekio
I quite like this kind of challenge :)

------
conkrete
▶ id(true ) // (4 chars)

▷ true

You win!

------
grabcocque
'Break JS to win!'

------
Tepix
It doesn't seem to work for me on Firefox and Chrome..?

~~~
kakarot
It wasn't working on either for me, so I came here to complain, went back and
it was suddenly working. Dunno what the issue was but keep trying maybe

~~~
vog
Yes, it seems to take quite a while to start up.

------
okket
This page only shows "return true to win" on a white background in Chrome?

~~~
tomsmeding
It loads eventually

~~~
scrollaway
Does it?

ReturnTrue:1 Fetch API cannot load
[https://bigger.alf.nu/db/true/H5VmsyVCBD62113H5Slu](https://bigger.alf.nu/db/true/H5VmsyVCBD62113H5Slu).
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin '[http://alf.nu'](http://alf.nu') is therefore not allowed access. If
an opaque response serves your needs, set the request's mode to 'no-cors' to
fetch the resource with CORS disabled.

~~~
pointytrees
it does

------
mk7
I am so unhappy, because I can not play such games with Java... ;-)

------
alexmorenodev
What the hell am I reading.

------
omaranto
The link points to a page that only contains the text "return true to win" in
large type on a white background. As with most modern art, I don't get it.

~~~
justinlardinois
Are you browsing with Javascript disabled?

~~~
omaranto
No.

