Hacker News new | ask | show | jobs
by fourspace 4541 days ago
I certainly can't get it to work. For the first problem, I tried:

  function one_bit(x) {
    return x & (x-1) == 0
  }
Only to see this error:

  Expected "}" or comment but "&" found.
WAT
3 comments

You can't use '-'.
That returns true or false, which I believe strictly speaking aren't numeric in Javascript. By definition of problem, probably should be:

function one_bit(x) { return x & (x-1) == 0 ? 1 : 0; }

It appears to have a limited JS validator to prevent you from using anything other than the limited operators it allows.
It really doesn't like having anything after "return" except a single value or variable.
That's not it. For example, it accepts "return x|x&x;" . The restriction is that only a handful of Javascript operations are allowed. Anything else gives a hard-to-understand error message.