Ternary operator or chosing from two arrays with the boolean as index

Posted by ajax333221 on Stack Overflow See other posts from Stack Overflow or by ajax333221
Published on 2012-11-07T22:46:25Z Indexed on 2012/11/07 23:00 UTC
Read the original article Hit count: 119

Which of these lines is more understandable, faster jsPerf, easier to maintain?:

arr = bol ? [[-2,1],[-1,2]] : [[-1,0],[-1,1]];
//or
arr = [[[-1,0],[-1,1]], [[-2,1],[-1,2]]][bol*1];

I usually write code for computers (not for humans), but this is starting to be a problem when I am not the only one maintaining the code and work for a team.

I am unsure, the first example looks neat but are two different arrays, and the second is a single array and seem to transmit what is being done easier. I also considered using an if-else, but I don't like the idea of writing two arr = ....

Or are there better options? I need serious guidance, I have never worried about others seeing my code.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about coding-style