Truncate a String, I've done, but one question left

Hello! Why if the given maximum string length num <= 3, then the addition of “…” not add to the string length in determining the truncated string?

Look, for example we have truncateString(“Absolutely Longer”, 2), so the num =2, 2<3, ok. Then we get “Ab”, because of .slice(0,2). But if we add 3 dots, the length’ll be 5, not 2. Who invented the rule which goes “if num <= 3, so the 3 dots won’t be counted”?

The author of the task It’s just an extra thing to take into account when writing a solution.

The lesson says not to count the extra added “…” 3 characters toward the truncated string length.

This means this.

If you have “0123456789”, a string length of 10.

And you put a limit of 7 on it It will become “0123456”.

Now add your trailing dots and you will get “0123456…” which has a length of 10 again.

Nothing has been accomplished. We want the length of our string to be 7 characters after the truncate, so we take our truncate tail and subtract it’s length from the length of our limit.

string.slice(0, 7-3).concat("...");

Now we get “0123…”

The lesson is asking us to reduce a string to a limiter and indicate that the string was reduced with trailing dots.

Now if we did this calculation if the limit was 3, well we’d just end up with “…” because 3 - 3 is an empty string plus “…”.

1 Like

but the below result examples in the challenge does not work like your explanation. That’s why I did not understand the number 3.

I think the challenge was changed later to avoid that confusion. Now the dots are not included in the string limit. At least I think that seeing the codes in the guide to solve the challenge