DEV Community

loading...
Cover image for Day 6 Challenge

Day 6 Challenge

hellodevworldblog profile image Hello Dev World Blog Originally published at hellodevworld.com ・1 min read

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.

Examples:

        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'
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

pic
Editor guide