13
2
There is a site called "Return True to Win" with interesting tasks for Javascript programmers. The goal is to find arguments to a given function that force it to return true.
The following is one of the tasks:
function total(x) {
return (x < x) && (x == x) && (x > x);
}
The users must find snippets for the value of x
that cause the function to return true. To test snippets, you call the function with your snippet as the parameter (i.e. total(<snippet>)
).
I found a 22-character solution:
{valueOf:_=>n++%3},n=0
Some people found the solution in 21 chars. I can't find out this solution. What is the solution in 21 chars?
3You should link the contest/page the task is taken from. – Emigna – 2018-01-17T20:05:37.637
1https://alf.nu/ReturnTrue – Oleg – 2018-01-17T20:08:29.293
You can't see the total task without solving previous tasks, You can find solutions on https://gist.github.com/OlegTar/cc79df913cafb3045474578e8ada8a3d
– Oleg – 2018-01-17T20:08:53.580@Riker Which JS engine are you using? Here is a working link.
– Arnauld – 2018-01-17T20:24:29.447Oh, I misunderstood how to run this. I thougth the code was supposed to replace the above code. – Rɪᴋᴇʀ – 2018-01-17T20:25:13.357
2
{valueOf:Math.random}
works from time to time ... but I suspect that would infringe some rule... (or maybe not?) – Arnauld – 2018-01-17T20:40:57.2371Those are decidedly tricky; out of the first 24, I can only answer 14... – Neil – 2018-01-17T22:03:05.127
4Salty dev note... having a function return Boolean called “total” is like nails on a chalkboard! – scunliffe – 2018-01-17T22:28:34.863
@scunliffe It's probably an adjective like in the algebraic structure total order. Total here means any two elements of a set are comparable. It's not the bottom line of a restaurant bill. Just my guess.
– ngn – 2018-01-21T04:05:25.603