3
GiddyNaya
24d

Interview Question:
Are there other options to make this go any shorter?
if (john == doe == max == paul == stella == false)
return "Not Okay";
return "Okay";

I did...
return (!john && !doe && !max && !paul && !stella) ? "Not Okay" : "Okay";

That was the shortest i could come up with... Maybe there is something shorter, dunno.

Comments
  • 11
    return (john || doe || max || paul || stella ? "" : "Not ") + "Okay";

    But that is only playing code golf.
    Normally, you want code to be readable instead of just being short.
  • 2
    My only 2p is that it's a stupid interview question. I wouldn't want to work anywhere that relied on micro-optimisation knowledge and code golfing over code readability.
  • 4
    return(john|doe|max|paul|stella)?'Okay':'Not Okay';

    Agreed with golf vs readability, though.
  • 2
    A == B == C == D doesn't mean that they're the same. It means that
    A == B && C == D || A != B && C != D
  • 1
    @Lor-inc Depends on language. Is it that way for java? (I don't have access to a jvm and didn't care enough to remedy that.)
  • 0
    This is the kind of questions that make me annoyed because it doesn't have anything to do with writing quality code.
Add Comment