Created
          December 5, 2015 18:26 
        
      - 
      
 - 
        
Save anonymous/f6677c0584ac0269966e to your computer and use it in GitHub Desktop.  
    http://www.freecodecamp.com/bskydive 's solution for Bonfire: Truncate a string
  
        
  
    
      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
    
  
  
    
  | // Bonfire: Truncate a string | |
| // Author: @bskydive | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string# | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function truncate(str, num) { | |
| return num>=str.length?str:str.substr(0,num-(num>=3?3:0))+'...'; | |
| } | |
| truncate("A-tisket a-tasket A green and yellow basket", 11); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment