Search code examples
optimizationpuzzle

Javascript Simple Puzzle


How can you optimize the following JS statement :

obj.endDate = obj.status && (obj.status.length == 2 || (obj.status.length == 1 && obj.status[0] == 0)) ? undefined : obj.endDate;

where

obj.status is of array type and is allowed to take only the following values:

  1. [1]
  2. [0]
  3. [1,0]
  4. undefined

obj.status may or may not be be undefined.


Solution

  • The problem isn't really optimizing it. The problem is that it is illegible. You or someone else will be grateful later when reading this code later to see it split up into some if/else or at least split it up a little with some clear naming.