Last active
May 11, 2018 16:23
-
-
Save AdrianSkar/3825c58d9f9ff01f9055c4d1459e276b to your computer and use it in GitHub Desktop.
[JS] exercise at fCC: https://codepen.io/adrianskar/pen/ELLvbP
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
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