Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.
Note that inserting the three dots to the end will add to the string length.
However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string.
Here are some helpful links:
function truncateString(str, num) {
if (str.length <= num) {
console.log(str);
overlay(str);
return str;
} else if (num <= 3) {
overlay(str.slice(0 , num ) + '...');
console.log(str.slice(0 , num ) + '...');
return str.slice(0 , num ) + '...';
} else {
overlay(str.slice(0 , num - 3) + '...');
console.log(str.slice(0 , num - 3) + '...');
return str.slice(0 , num - 3) + '...';
}
}