function truncate(str, num) {
if (str.length >= num) {
if (num > 3) {
str.substr(0, num - 3) + '...';
} else {
str.substr(0, num) + '...';
}
} return str;
}
console.log(truncate("A-tisket a-tasket A green and yellow basket", 11));
It returned me the original string A-tisket a-tasket A green and yellow basket. I wonder waht's the problem here.
return str.substr(0, num - 3) + '...';