Skip to content

Instantly share code, notes, and snippets.

@AdrianSkar
Last active May 11, 2018 16:23
Show Gist options
  • Save AdrianSkar/3825c58d9f9ff01f9055c4d1459e276b to your computer and use it in GitHub Desktop.
Save AdrianSkar/3825c58d9f9ff01f9055c4d1459e276b to your computer and use it in GitHub Desktop.
function truncateString(str, num) {
if (num <= 3) {
return str.substr(0, num) + '...';
}
if (num >= str.length) {
return str;
}
return str.substr(0, num - 3) + '...';
}
truncateString('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