Want to print out all odd numbers from 1 to 100? Easy:
for(_=[];_<+!![]+""+[]*[]+[]*[];_++)(_%+(!![]+!![])?console.log(_):[]);
Actually, I prefer this one:
for(_=[];_<+!![]+""+[]*[]+[]*[];_++%+(!![]+!![])?[]:console.log(_));
Or this one without the “undefined” when run in a browser console:
for(_=[];_<+!![]+""+[]*[]+[]*[]-!![]-!![];_++%+(!![]+!![])?[]:console.log(_));_+!![]
Wtf people, can somebody explain?
_ is a variable name, [] becomes 0 when converted to an integer, !![] becomes 1. The + “” + means that the integers 1, 0, 0 get converted to a string - “100”, which gets converted back to an integer because it’s in the for loop. And there’s various other horrible conversions going on to make it all work.
I used to work at a company that used XSLT. They know that it’s an obscure language that probably none of the potential candidates have ever worked with. But it’s easy enough to learn the basics in an hour or two.
So the entry test was to strip some tags from an XML file. You had a day or two (maybe more) to do it. My solution wasn’t ideal, I didn’t use several of the shortcuts available in the language. But at least it did what it was supposed to.
A few weeks after I had started working there my boss came up to me, visibly frustrated and asked me whether the test was too hard. Thinking back on my problems I replied that maybe having the desired output ready so that you could test your own solution against it might be nice. But my boss’s problem was that none of the last 5 candidates could even send in a solution that would run.
You had so much time, and running an XSLT script is really easy and takes no time at all. And for some inane reason these people couldn’t even manage to test their code and still decided to send it in.
And I thought I was an idiot when I didn’t know if it was spelled grey or gray in CSS during the in-person interview.
It is very good test for the ability to research, I think. The amount of people who painstakingly went through some video tutorial on PHP and are now developers is insane. I’m sure there’s place in the market for them (writing Wordpress themes/plugins, for example), but it’s hard to find a programmer with ability to think these days. Not because people are more stupid, but because every other person is a programmer now.