Why does this pass all of the tests except “truncateString(“Absolutely Longer”, 2) should return “Ab…”.”?
function truncateString(str, num) {
if (num >= str.length) {
return str;
} else if (str.length <= 3){
strSlice = str.slice(0, num);
shortString = strSlice + "...";
return shortString;
}
else {
strSlice = str.slice(0, num - 3);
truncatedString = strSlice + "...";
return truncatedString;
}
}
truncateString("Peter Piper picked a peck of pickled peppers", 14);