Last active
          December 5, 2016 14:12 
        
      - 
      
 - 
        
Save andreasvirkus/445feab4dbdadd4d2f632a3d1ef72756 to your computer and use it in GitHub Desktop.  
  
    
      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
    
  
  
    
  | var counts = [4, 9, 15, 6, 2], | |
| goal = 5; | |
| var closest = counts.reduce(function (prev, curr) { | |
| return (Math.abs(curr - goal) < Math.abs(prev - goal) ? curr : prev); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment