Tell us what’s happening:
This is the FCC Advanced:
function truncateString(str, num) {
if (str.length <= num) {
return str;
} else {
return str.slice(0, num > 3 ? num - 3 : num) + '...';
}
}
I just wanna hear your thoughts about the Title question?
The proposed solution:
1)It should be a bit faster
2) use two methods instead of nested conditionals
3) is more readable
Your code so far
function truncateString(str, num) {
let x;
num < str.length ? x = str.slice(0, num).concat("...") : x = str.slice(0, num)
return x
}
truncateString("A-", 1) // --> A...
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 OPR/62.0.3331.119
.
Link to the challenge: