Skip to content

Instantly share code, notes, and snippets.

@manojrammurthy
Created December 4, 2015 04:40
Show Gist options
  • Save manojrammurthy/f4093a61613367f415b6 to your computer and use it in GitHub Desktop.
Save manojrammurthy/f4093a61613367f415b6 to your computer and use it in GitHub Desktop.
bonfire freecodecamp basic algorithm javascript
function truncate(str, num) {
if(str.length<=num)
return str;
if (num <= 3)
return str.substr(0,num) + "...";
return str.substr(0,num-3) + "...";
}
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