Skip to content

Instantly share code, notes, and snippets.

Created December 5, 2015 18:26
Show Gist options
  • Save anonymous/f6677c0584ac0269966e to your computer and use it in GitHub Desktop.
Save anonymous/f6677c0584ac0269966e to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/bskydive 's solution for Bonfire: Truncate a string
// 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