Tell us what’s happening:
As always, after my solution works I go to see a hint for ways I could’ve done it better. The solution there got me a bit confused. I can’t find how is this better or more reliable than my solution and I’d just like some more insight if and why is one better than the other. Thanks
HintSolultion:
// Clear out that junk in your trunk
if (str.length > num && num > 3) {
return str.slice(0, (num - 3)) + '...';
} else if (str.length > num && num <= 3) {
return str.slice(0, num) + '...';
} else {
return str;
}
}
Your code so far
function truncateString(str, num) {
// Clear out that junk in your trunk
return str.length > num ? str.slice(0, num) + "..." : str;
}
truncateString("A-tisket a-tasket A green and yellow basket", 8);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge: