Deviopath › JavaScript

Truncate a String

Easy · Strings

Write a function truncate that shortens a string to at most maxLength characters.

If the string is longer than maxLength, keep the first maxLength characters and add "..." at the end. Otherwise return the string unchanged.

Next: Capitalize Words