Created
November 14, 2015 23:05
-
-
Save codebubb/a3ef3da0fcc3175a45e9 to your computer and use it in GitHub Desktop.
This file contains 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: @codebubb | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-truncate-a-string?solution=function%20truncate(str%2C%20num)%20%7B%0A%20%20%2F%2F%20Totally%20unclear!%0A%20%20%20%20return%20str.length%20%3E%20num%20%3F%20num%20%3C%3D%203%20%3F%20str.slice(0%2C%20num)%20%2B%20%22...%22%20%3A%20str.slice(0%2C%20num%20-3)%20%2B%20%22...%22%20%3A%20str%3B%0A%7D%0A%0Atruncate(%22Absolutely%20Longer%22%2C%202)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function truncate(str, num) { | |
// Totally unclear! | |
return str.length > num ? num <= 3 ? str.slice(0, num) + "..." : str.slice(0, num -3) + "..." : str; | |
} | |
truncate("Absolutely Longer", 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment