Basic Algorithm Scripting: Truncate a String : Given Answer doesn't pass

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string

The answer given under the hint does not pass all tests.

Yes, some of those hints are outdated. I think that the hints are for how the problem used to be - I seem to remember solving it that way. The problem used to be more complicated.

The explanation on the challenge says:

Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.

And the explanation in the hint is:

  • First we start off with a simple if statement to determine one of three outcomes…
  • If our string length is greater than the num we want to truncate at, and our truncate point is at least three characters or more into the string, we return a slice of our string starting at character 0, and ending at num - 3. We then append our '...' to the end of the string.
  • etc.

Notice that second bullet point - it is a different problem. Unlike the old problem where there were three cases to worry about, now there are only two. If it is less than or equal to num just return it. Otherwise truncate it to num, add the ellipsis and return that. You don’t have to worry about the affect of the length of the ellipsis.

FCC is a volunteer non-profit. The curriculum is constantly being updated and that is where the priority is. There isn’t as much priority placed on monitoring all the hints.

2 Likes