Freecodecamp: Advance code solution is not able to pass first two test cases.

Created on 23 Aug 2019  路  3Comments  路  Source: freeCodeCamp/freeCodeCamp

error
Describe your problem and how to reproduce it:
The advance code solution provided in Truncate a String is not able to pass first two test-cases. If you find anything wrong please forgive me.

Add a Link to the page with the problem:
https://guide.freecodecamp.org/certifications/javascript-algorithms-and-data-structures/basic-algorithm-scripting/truncate-a-string/

Tell us about your browser and operating system:

  • Browser Name: Not necessary.
  • Browser Version: Not necessary.
  • Operating System: Not necessary.

If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box):

resolveshipping

All 3 comments

If you think the problem mentioned above is valid and you want a solution to replace. Here is my code which passed all the test cases.

Code:
function truncateString(str, num) {
// Clear out that junk in your trunk
if(str.length <= num){
return str
}
return str.slice(0, num) + "...";
}

truncateString("A-tisket a-tasket A green and yellow basket", 8);

Proof:
correct

The guide is being moved over to the forum. Here is the post for that challenge. Both of those solutions work, so when the current guide is removed - this shouldn't be an issue.

This can be closed as we are just waiting for master to be shipped to production.

Was this page helpful?
0 / 5 - 0 ratings