title: Is there an alternative to using IF / ELSE statements
body: <p><strong>Question</strong></p>
  
  <p>More out of curiosity, but I was wondering how to refactor an if statement to something cleaner / less brittle. From what I have read, <strong>polymorphism</strong> could have a use?</p>
  
  <p>In the example I only want to return the first car if <code>color:'red'</code> is true.</p>
  
  <p><strong>Coffeescript</strong></p>
  
  <pre><code>example: () -&gt;
      cars = [{color:'red', reg:'111'},{color:'blue', reg:'666'}]
      if cars[0].color is 'red' 
      then cars[0]
      else cars[1]
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>  example: function() {
      var cars = [{color:'red',reg:'111'},{color:'blue',reg:'666'}];
      if (cars[0].color === 'red') {
        return cars[0];
      } else {
        return cars[1];
      }
    }
  </code></pre>
  
  <p><em>I understand this question maybe closed or moved due to the ambiguous nature</em></p>