Created
December 4, 2015 04:40
-
-
Save manojrammurthy/f4093a61613367f415b6 to your computer and use it in GitHub Desktop.
bonfire freecodecamp basic algorithm javascript
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 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