Day 6 Challenge

Happy Day 6! Today we are going back to basics. This challenge can easily be applied to front end as well as backend.

The Problem

Create a function that accepts a string and a number. The function must return the given string truncated to the maximum length (number that was passed in) followed by "...". If the string is shorter than the passed maximum length return the passed string.

Example:

        truncate('It works on my machine', 8) // 'It works...'
        truncate('It’s not a bug – it’s an undocumented feature', 14) // 'It’s not a bug...'
        truncate('In order to understand recursion, one must first understand recursion', 'In order to understand recursion, one must first understand recursion'.length)           // 'In order to understand recursion, one must first understand recursion'
        truncate('The cheapest, fastest, and most reliable components are those that aren’t there', 82) //'The cheapest, fastest, and most reliable components are those that aren’t there'
    
Previous
Previous

How to Truncate a String in JavaScript

Next
Next

Snail Array Challenge Solution JavaScript