I solved the exercise as per the given instructions, passing all tests, with the following code
then checked the hint section just to compare my method and the fcc solution, and there seemed to be an additional condition for the exercise in the hint section that was not in the exercise for me.
I’m referring to the three dots being included in the final truncated string length(in which case the actual truncated string would have a length of n-3 where n is the desired final length, to accomodate for the three dots)
The exercise had no mention of the three dots being included in the truncated string length, and for all the examples and test cases, the dots were added after the string was truncated.
truncateString(“Peter Piper picked a peck of pickled peppers”, 11)` should return “Peter Piper…”
was one of the test cases. here “Peter Piper” has a length of 11 and the three dots are added afterwards, bringing the total length of the output to 14.
however the hint section seems to imply that the result should be “Peter Pi…”, which has a total length of 11.
Now i did some trawling in the forums and it appears that the exercise used to specify that the three dots be included in the final truncated string length, but was changed later on.
The answer provided in the hint section actually does not pass the current test cases of the exercise, and could potentially be very confusing for people attempting the exercise.
I am not sure how to address this to the mods/editors of fcc so i’m making a general post. if anyone knows how to direct this to them, please inform me.