Created
December 9, 2015 07:18
-
-
Save anonymous/f19e9d5f106590b29f32 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/kkas 's solution for Bonfire: Truncate a string
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
// Bonfire: Truncate a string | |
// Author: @kkas | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function truncate(str, num) { | |
// Clear out that junk in your trunk | |
var len = num > 3 ? num - 3 : num; | |
return str.length > num ? str.slice(0, len) + "..." : str; | |
} | |
//truncate("A-tisket a-tasket A green and yellow basket", 11); | |
//truncate("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length); | |
truncate("A-", 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment