Last active
          December 14, 2015 15:58 
        
      - 
      
 - 
        
Save user24/5111233 to your computer and use it in GitHub Desktop.  
    Code Clarity by hoisting logic into nicely named variables
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Succinct, does not create strictly unnecessary variables | |
| // but not easy to read | |
| if((a.notes && a.notes.trim() != "") && (b.notes && b.notes.trim() != "")) { | |
| skip = true; | |
| console.log('too many notes - skipping'); | |
| } | |
| // Verbose, creates two vars which are not really needed | |
| // but it's instantly clear what the 'if' is doing | |
| var aHasNotes = (a.notes && a.notes.trim() != ""); | |
| var bHasNotes = (b.notes && b.notes.trim() != ""); | |
| if(aHasNotes && bHasNotes) { | |
| skip = true; | |
| console.log('too many notes - skipping'); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
I would probably move the conditions into a method of my object.
So then my implimentation is simpler to understand.
I can then re-use this logic elsewhere in the codebase.