Skip to content

Instantly share code, notes, and snippets.

@ceaksan
Created September 18, 2015 14:23
Show Gist options
  • Save ceaksan/3b16bb4392b22fe75812 to your computer and use it in GitHub Desktop.
Save ceaksan/3b16bb4392b22fe75812 to your computer and use it in GitHub Desktop.
function truncate(str, num) {
if(str.length > num) str = str.slice(0, num - 3) + '...';
return str;
}
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